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 pipe = (...fns) => fns.reduce((f, g) => (...args) => g(f(...args))); | |
| const compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args))); | |
| // Example | |
| const addFoo = str => str + 'foo'; | |
| const addBar = str => str + 'bar'; | |
| const addFoobar = pipe(addFoo, addBar); | |
| const addBarfoo = compose(addFoo, addBar); | |
| addFoobar('hello ') // hello foobar | |
| addBarfoo('hello ') // hello barfoo |
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 lotto(amountOfNumbers, from, to) { | |
| const numbers = []; | |
| for (let i = 0; i < amountOfNumbers; i++) { | |
| let number = null; | |
| while (number === null || numbers.indexOf(number) > -1) { | |
| number = Math.floor(Math.random() * (to - from + 1)) + from; | |
| } | |
| numbers.push(number); | |
| } | |
| return numbers.sort((a, b) => a - b); |