Last active
February 21, 2022 08:28
-
-
Save ahangarha/aeca2ffff451cd2ee96c1ffaa233baa4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// == EXAMPLE 1 ==================================== | |
const pets = ['Cat', 'Dog', 'Bird', 'Fish', 'Frog', 'Hamster', 'Pig', 'Horse', 'Lion', 'Dragon']; | |
// Print all pets | |
console.log(pets[0]); | |
console.log(pets[1]); | |
console.log(pets[2]); | |
console.log(pets[3]); | |
//... | |
// == EXAMPLE 2 ==================================== | |
const greet = (message, name) => { | |
console.log(`${message}, ${name}!`) | |
} | |
greet('Hello', 'John'); | |
greet('Hola', 'Antonio'); | |
greet('Ciao', 'Luigi') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The code in the example 1 is not DRY. Not only we need to repeat same lines of code again and again, we need to modify them manually. This is not scalable and also maintainable.
This is a DRY code which does the same thing:
The code in the example 2 also is not DRY. We can make it better by looping over and object: