Skip to content

Instantly share code, notes, and snippets.

@melashu
Created August 15, 2022 19:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save melashu/bf50cb89aa3b2f2c870f64af727b7712 to your computer and use it in GitHub Desktop.
Save melashu/bf50cb89aa3b2f2c870f64af727b7712 to your computer and use it in GitHub Desktop.
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])
}
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