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 animals = ["elephant", "monkey", "snake", "lion"]; | |
| for (let index = animals.length; index > 0; index--) { | |
| animals[index] = animals[index - 1]; | |
| } | |
| animals[0] = "macaw"; | |
| console.log(animals); // will return [ 'macaw', 'elephant', 'monkey', 'snake', 'lion' ] |
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 greet = name => ({ | |
| sayHello: () => `Hello ${name}!`, | |
| sayGoodbye: () => `Goodbye ${name}!`, | |
| }); | |
| const run = () => { | |
| const greetRicardo = greet("Ricardo"); | |
| console.log(greetRicardo.sayHello()); | |
| console.log(greetRicardo.sayGoodbye()); |
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
| class greet { | |
| constructor(name) { | |
| this.name = name; | |
| } | |
| sayHello() { | |
| return `Hello ${this.name}!`; | |
| } | |
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 greetRicardo = { | |
| sayHello() { | |
| return `Hello Ricardo!`; | |
| }, | |
| sayGoodbye() { | |
| return `Goodbye Ricardo!`; | |
| }, | |
| }; |
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
| class Directory { | |
| constructor(name) { | |
| this.setName(name); | |
| this.children = []; | |
| return this; | |
| } | |
| add(element) { | |
| this.children.push(element); |
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
| class Car { | |
| constructor({ model, year, manufacturer }) { | |
| this.setYear(year); | |
| this.setManufacturer(manufacturer); | |
| this.setModel(model); | |
| } | |
| setModel(model) { | |
| this.model = model; | |
| } |
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
| class User { | |
| constructor({ name, continent, email }) { | |
| this.setName(name); | |
| this.setEmail(email); | |
| this.setContinent(continent); | |
| } | |
| setName(name) { | |
| this.name = name; | |
| } |
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
| class User { | |
| constructor({ name, continent, email, allowCookies = true }) { | |
| this.setName(name); | |
| this.setEmail(email); | |
| this.setContinent(continent); | |
| if (continent === "Europe") { | |
| this.setAllowCookies(allowCookies); | |
| } | |
| } |
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
| class SimpleEmailValidationService { | |
| isValid(email) { | |
| return email.indexOf("@") > 2; | |
| } | |
| } | |
| class SimpleZipCodeValidationService { | |
| isValid(zipCode) { | |
| //A98 HNA23 | |
| return zipCode.length === 8; |
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
| class SimpleEmailValidationService { | |
| isValid(email) { | |
| return email.indexOf("@") > 2; | |
| } | |
| } | |
| class SimpleZipCodeValidationService { | |
| isValid(zipCode) { | |
| //A98 HNA23 | |
| return zipCode.length === 8; |