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
| <button class="one">18</button> | |
| <button class="two">22</button> | |
| <div id="changes"> | |
| </div> |
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
| function factorial( n ) { | |
| if ( n === 1 ) { | |
| return 1; | |
| } | |
| return n * factorial( n - 1 ); | |
| } | |
| factorial(6) // 720 | |
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
| // example 1 // simple composition | |
| function concatName(firstname, lastname) { | |
| return `${firstname} ${lastname}`; | |
| } | |
| function injetDom(element) { | |
| document.querySelector('body').innerHTML = element; | |
| } | |
| injectDom(concatName('sebastian', 'yabiku')) |
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
| // inmmutability | |
| const resultAccounts = ['12367', '12368', '22367', '22368', '32367', '32368']; | |
| function AccountsByNumberInit(account, number) { | |
| return account.substring(0,1) === number | |
| } | |
| const accountsStartOne = resultAccounts.filter(account => AccountsByNumberInit(account, '1')); | |
| const accountsStartTwo = resultAccounts.filter(account => AccountsByNumberInit(account, '2')); | |
| const accountsStartThree = resultAccounts.filter(account => AccountsByNumberInit(account, '3')); |
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
| let numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; | |
| // filter | |
| let filterNumber = numbers.filter((number) => number > 5) // 6, 7, 8, 9, 10 | |
| // reduce | |
| let reduceNumber = numbers.reduce((previousNumber, currentNumber) => previousNumber + currentNumber); // 10 | |
| // reduce initial | |
| let reduceInitial = numbers.reduce((previousNumber, currentNumber) => previousNumber + currentNumber, 10); // 20 |
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
| // assign to variables | |
| const f = (m) => console.log(m) | |
| f('Test') | |
| // assing in objet | |
| const obj = { | |
| f(m) { | |
| console.log(m) | |
| } | |
| } |
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
| // function pure | |
| function add(x) { | |
| return x + 2; | |
| } | |
| // function not pure | |
| let y = 2; | |
| function add2(x) { | |
| return x + y; | |
| } |
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
| let animals = [ | |
| { | |
| name: 'Rin tin tin', | |
| species: 'dog' | |
| }, | |
| { | |
| name: 'gardfield', | |
| species: 'cat' | |
| }, | |
| { |
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
| // prototype heritage | |
| function Animal(type, species){ | |
| this.type = type; | |
| this.species = species; | |
| } | |
| Animal.prototype.say = function() { | |
| return `The ${this.type} is a ${this.species} and say ${say}`; | |
| } |
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
| let numbers = [12, 32, 45, 13, 19]; | |
| let add = 0; | |
| let average = 0; | |
| for (let i= 0; i < marks.length; i++) { | |
| add += marks[i]; | |
| } | |
| average = add / marks.length; |