Skip to content

Instantly share code, notes, and snippets.

@braincee
Created May 2, 2022 11:21
Show Gist options
  • Select an option

  • Save braincee/3cb36e2a6089ec1e1dbea6bea36d1aae to your computer and use it in GitHub Desktop.

Select an option

Save braincee/3cb36e2a6089ec1e1dbea6bea36d1aae to your computer and use it in GitHub Desktop.
Checking if files are DRY or not.
// the animals were having the same font-family and font-size
.cat, .dog, .dragon {
font-family: "Times New Roman", Times, serif;
font-size: 1rem;
}
.cat {
color: #FFF;
}
.dog {
color: #000;
}
.dragon {
color: #009933;
}
const pets = ['Cat', 'Dog', 'Bird', 'Fish', 'Frog', 'Hamster', 'Pig', 'Horse', 'Lion', 'Dragon'];
// To make the syntax short in DRY form, we can use the pets.forEach
pets.forEach(pet => console.log(pet))
//This code is DRY
// Same font-family value to all elements, the value for the background and color are different,
.greetings {
font-family: Arial, sans-serif;
font-size: 1.5rem;
}
.greetings.english {
background-color: #000;
color: #FFF;
}
.greetings.spanish {
background-color: #FFF;
color: #000;
}
//The code is DRY.
// We use functions to avoid repeating the same process to display the message and the name of the person.
// Instead of rewriting the same code, we only need to call the function and pass to it the message and name.
const greetings = [
{ message: 'Hello', name: 'John' },
{ message: 'Hola', name: 'Antonio' },
{ message: 'Ciao', name: 'Luigi' },
];
greetings.forEach((object) => greet(object.message, object.name));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment