Last active
November 12, 2022 02:13
-
-
Save abdallahmalima/d6eb3b1a1a912666dcdfadc79cd15331 to your computer and use it in GitHub Desktop.
Test if code is DRY
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
/*=======================================*\ | |
this code does Not follow DRY principle | |
\*=======================================*/ | |
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]); | |
console.log(pets[4]); | |
console.log(pets[5]); | |
console.log(pets[6]); | |
console.log(pets[7]); | |
console.log(pets[8]); | |
console.log(pets[9]); | |
/*=======================================*\ | |
this code follow DRY principle | |
\*=======================================*/ | |
const pets = ['Cat', 'Dog', 'Bird', 'Fish', 'Frog', 'Hamster', 'Pig', 'Horse', 'Lion', 'Dragon']; | |
pets.forEach(pet=>console.log(pet)); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment