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 compose = | |
(...fns) => | |
(x) => | |
fns.reduceRight((res, fn) => fn(res), x); |
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 discount = compose(normalizePrice, divide100, multiply20); | |
discount(200.0); //40.00 |
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 compose = (a, b, c) => (x) => a(b(c(x))); |
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
// result = a(b(c(x))) | |
const discount = normalizePrice(divide100(multiply20(200))); // 40.00 |
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 multiply20 = (price) => price * 20; | |
const divide100 = (price) => price / 100; | |
const normalizePrice = (price) => price.toFixed(2); |
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 result = [...new Set([...firstArr, ...secondArr])] |
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 concatArr = firstArr.concat(secondArr) | |
const result = concatArr.filter((item, idx) => concatArr.indexOf(item) === idx) |
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 result = [] | |
for (let i = 0; i < firstArr.length; i++) { | |
if (result.indexOf(firstArr[i]) == -1) result.push(firstArr[i]) | |
} | |
for (let i = 0; i < secondArr.length; i++) { | |
if (result.indexOf(secondArr[i]) == -1) result.push(secondArr[i]) | |
} |
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 firstArr = new Array(200).fill(undefined).map((val, i) => `item${i}`) | |
const secondArr = new Array(250).fill(undefined).map((val, i) => `item${i}`) |
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 firstArr = new Array(200).fill(undefined).map((val, i) => `item${i}`) | |
const secondArr = new Array(250).fill(undefined).map((val, i) => `item${i}`) | |
const result = secondArr.reduce( | |
(acc, item) => { | |
return acc.includes(item) ? acc : [...acc, item] | |
}, | |
[...firstArr] | |
) |