Skip to content

Instantly share code, notes, and snippets.

@HAMMAS-SALEEM
Last active January 19, 2022 15:09
Show Gist options
  • Save HAMMAS-SALEEM/7d3b85c5efc79004cc9658ec44972dd7 to your computer and use it in GitHub Desktop.
Save HAMMAS-SALEEM/7d3b85c5efc79004cc9658ec44972dd7 to your computer and use it in GitHub Desktop.
Example 2: JavaScript
const greet = (message, name) => {
console.log(`${message}, ${name}!`)
}
Here's my solution
const greet = (message, name) =>console.log(`${message}, ${name}!`);
Example 2: CSS
.greetings {
font-family: Arial, sans-serif;
font-size: 1.5rem;
}
.greetings.english {
background-color: #000;
color: #FFF;
}
.greetings.spanish {
background-color: #FFF;
color: #000;
}
This solution is DRY. Because here we can't see any duplicate code. Every line of code is different.
Example 1: JavaScript
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]);
This solution for consoling pets array is not DRY at all. One more thing this code will not run because there is an syntax error in
array initialization. It is missing a comma after 'Horse'.
Here's my solution.
const petConsole = ()=>pets.forEach(item=>console.log(item));
Example 1: CSS
.cat {
font-family: "Times New Roman", Times, serif;
font-size: 1rem;
color: #FFF;
}
.dog {
font-family: "Times New Roman", Times, serif;
font-size: 1rem;
color: #000;
}
.dragon {
font-family: "Times New Roman", Times, serif;
font-size: 1rem;
color: #009933;
}
Here's my solution
.cat, .dog, .dragon {
font-family: "Times New Roman", Times, serif;
font-size: 1rem;
}
.cat {
color: #FFF;
}
.cat {
color: #000;
}
.cat {
color: #009933;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment