Skip to content

Instantly share code, notes, and snippets.

@JuniorGarciaRodriguez
Last active May 8, 2023 15:27
Show Gist options
  • Save JuniorGarciaRodriguez/f10a15fdb581d5ace497038e047b1634 to your computer and use it in GitHub Desktop.
Save JuniorGarciaRodriguez/f10a15fdb581d5ace497038e047b1634 to your computer and use it in GitHub Desktop.
Is it DRY? m2w3d1
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]);
...
const greet = (message, name) => {
console.log(`${message}, ${name}!`)
}
greet('Hello', 'John');
greet('Hola', 'Antonio');
greet('Ciao', 'Luigi')
@JuniorGarciaRodriguez
Copy link
Author

Example 1 isn't DRY. It's repeating a console.log call for every element of the array instead of using a loop

Example 2 is DRY

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment