Created
March 13, 2020 05:51
-
-
Save jsmanifest/eaa4d24ecc44f69da5f5481c41b2f3c9 to your computer and use it in GitHub Desktop.
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 compose = (...fns) => (arg) => | |
fns.reduceRight((acc, fn) => (fn ? fn(acc) : acc), arg) | |
const add = (num1) => (num2) => num1 + num2 | |
const multiply = (num1) => (num2) => num1 * num2 | |
const subtract = (num1) => (num2) => num1 - num2 | |
const composedOperations = compose(add(5), multiply(2), subtract(3)) | |
const compute = (arr, initialNum = 0) => | |
arr.reduce((acc, val) => composedOperations(acc), initialNum) | |
console.log(compute([-10, 25, 55, 22], 6)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment