Created
August 15, 2022 19:59
-
-
Save melashu/bf50cb89aa3b2f2c870f64af727b7712 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
const pets = ['Cat', 'Dog', 'Bird', 'Fish', 'Frog', 'Hamster', 'Pig', 'Horse', 'Lion', 'Dragon']; | |
console.log(pets[0]); | |
console.log(pets[1]); | |
console.log(pets[2]); | |
console.log(pets[3]); | |
//This code cant fullfil DRY. The code is repeated but we can minimize it. The following code snippt | |
//is the DRY vesrion of the above code. | |
for(let i=0;i<pets.length;i++){ | |
console.log(pets[i]) | |
} |
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
const greet = (message, name) => { | |
console.log(`${message}, ${name}!`) | |
} | |
greet('Hello', 'John'); | |
greet('Hola', 'Antonio'); | |
greet('Ciao', 'Luigi') | |
//The above code fullfill DRY principle because | |
//each object reuse the same console.log(). | |
//The object is created based on the template object. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment