This file contains 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 numbers = [1,2,3,4,5,5,4]; | |
const uniqueItems = Array.from(new Set(numbers)); | |
console.log(uniqueItems); |
This file contains 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 createAdder = (base) => (secondary) => secondary + base; | |
const numbers = [1,2,3,4,5]; | |
const fns = numbers.map(item => createAdder(item)); | |
const pipe = (...fns) => x => fns.reduce((y, f) => f(y), x); | |
const addAll = pipe(...fns); | |
// console.log(addAll(6)); |
This file contains 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 arr = [1,2,3]; | |
const arr2 = [4,5,6,[7], [8]]; | |
console.log(arr.concat(arr2)); // not flattened | |
console.log([...arr, ...arr2]); // not flattened | |
console.log(arr.concat(...arr2)); // flattened |
This file contains 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 is not my code, I've just saved it for myself. Origin: https://github.com/leighhalliday/reduce-example | |
const people = [ | |
{ id: "1", name: "Leigh", age: 35 }, | |
{ id: "2", name: "Jenny", age: 30 }, | |
{ id: "3", name: "Heather", age: 28 }, | |
]; | |
let result; |
This file contains 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 array = [ | |
1, 2, 3, 4, | |
]; | |
const createAsyncfunction = number => new Promise((resolve, reject) => { | |
const tiemout = Math.floor(Math.random() * Math.floor(10)); | |
if (number === 3) reject('Bad number'); | |
else { | |
setTimeout(() => { | |
console.log('number is printed: ', number); |