Created
August 15, 2022 18:02
-
-
Save AlucardSanin/f045ffbb990d751ecd3cd62763e55bc8 to your computer and use it in GitHub Desktop.
Is it DRY?
This file contains 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']; | |
// Print all pets | |
console.log(pets[0]); | |
console.log(pets[1]); | |
console.log(pets[2]); | |
console.log(pets[3]); | |
... | |
.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; | |
} | |
//////////////////////////////////////////////////////////////////////////////////////// | |
Is it DRY? | |
No is not- | |
A for Each should be use, even a for loop could have done an shorter approach | |
pets.forEach(print (pet){ | |
console.log(pet); | |
} | |
CSS could also be improved this way: | |
.cat, .dog, .dragon{ | |
font-family: "Times New Roman", Times, serif; | |
font-size: 1rem; | |
} | |
For the styles, but still have to call each one for colors. | |
.cat { | |
color: #FFF; | |
} | |
.dog { | |
color: #000; | |
} | |
.dragon { | |
color: #009933; | |
} |
This file contains 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 only way I see this can be improved is to load a default value into the function, so we can delete a greet function call. | |
const greet = (message = 'Hello' , name = 'John') => { | |
console.log(`${message}, ${name}!`) | |
} | |
greet('Hola', 'Antonio'); | |
greet('Ciao', 'Luigi') | |
////////////////////////////////////////////////////// | |
.greetings { | |
font-family: Arial, sans-serif; | |
font-size: 1.5rem; | |
} | |
.greetings.english { | |
background-color: #000; | |
color: #FFF; | |
} | |
.greetings.spanish { | |
background-color: #FFF; | |
color: #000; | |
} | |
For this CSS I can't find a way to improve it | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment