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
| 'use strict'; | |
| function str(strings, ...values) { | |
| let str = ""; | |
| values.forEach((val, i) => { | |
| str += strings[i]; | |
| str += values[i]; | |
| }) |
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 counter = (state = 0, action) => { | |
| switch (action.type) { | |
| case 'INCREMENT': | |
| return state + 1; | |
| case 'DECREMENT': | |
| return state - 1; | |
| default: | |
| return state; | |
| } | |
| } |
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 addCounter = (list, 0) => { | |
| //return list.concat([0]); | |
| return [...list, 0]; | |
| }; |
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 removeCounter = (list, i) => { | |
| /*return list.slice(0, i) | |
| .concat(list.slice(i + 1))*/ | |
| return [ | |
| ...list.slice(0, i), | |
| ...list.slice(i + 1) | |
| ]; | |
| } |
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 incrementCounter = (list, i) => { | |
| /*return list.slice(0, i) | |
| .concat(list[i] + 1) | |
| .concat(list.slice(i + 1));*/ | |
| return [ | |
| ...list.slice(0, i), | |
| list[i] + 1, | |
| ...list.slice(i + 1) | |
| ] |
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 testAddCounter = () => { | |
| const listBefore = []; | |
| const listAfter = [0]; | |
| deepFreeze(listBefore); | |
| expect( | |
| addCounter(listBefore) | |
| ).toEqual(listAfter); | |
| }; |
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 toggleTodo = (todo) => { | |
| /*mutated version | |
| todo.completed = !todo.completed; | |
| return todo;*/ | |
| /*Object.assing version | |
| return Object.assign({}, todo, { | |
| completed: !todo.completed | |
| });*/ |
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
| Object.defineProperty(obj, prop, descriptor) |
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 o1 = { | |
| prop: 'prop' | |
| } | |
| const o2 = Object.setPrototypeOf({ | |
| prop2: 'prop2' | |
| }, o1); | |
| console.log(o2.prop2, o2.prop) |
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 multiple(a, b) { | |
| return a * b; | |
| } | |
| function square(n) { | |
| return multiple(n, n); | |
| } | |
| function printSquare(n) { | |
| console.log(square(n)); |