Created
May 5, 2016 23:34
-
-
Save karenpeng/203b07b9baa2b1b520d3af4b6fcd5a17 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
function functionsProcessor(funcArr, initValue, ...args) { | |
if(!funcArr.length) return initValue | |
var cur = funcArr.shift() | |
return functionsProcessor(funcArr, cur(initValue, ...args), ...args) | |
} | |
function functionsProcessor(funcArr, initValue, ...args) { | |
for(var i = 0; i < funcArr.length; i++){ | |
initValue = funcArr[i](initValue, ...args) | |
} | |
return initValue | |
} | |
function functionsProcessor(funcArr, initValue, ...args) { | |
return funcArr.reduce(function eachFunction(result, func) { | |
return func(result, ...args); | |
}, initValue); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment