Created
May 2, 2022 11:21
-
-
Save braincee/3cb36e2a6089ec1e1dbea6bea36d1aae to your computer and use it in GitHub Desktop.
Checking if files are DRY or not.
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
| // 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; | |
| } |
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']; | |
| // To make the syntax short in DRY form, we can use the pets.forEach | |
| pets.forEach(pet => console.log(pet)) |
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
| //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; | |
| } |
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
| //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