Created
October 19, 2017 05:35
-
-
Save fauxneticien/34531d1e255bb994de60aea34cb1a83a to your computer and use it in GitHub Desktop.
Ecuder — the opposite of reduce
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
/* | |
// Helper to split an initial object into a nested array | |
// by Mark Ellison <https://github.com/tyrannomark> mostly! | |
ecuder([x => x.split(" ")])("one two") | |
ecuder([x => x.split(" "), x => x.split("")])("one two") | |
ecuder([x => x.split(/\.\s?/), x => x.split(" "), x => x.split("")])("sentence one. sentence two") | |
*/ | |
function ecuder(funcs_array, initial_obj) { | |
return function ecuderR(initial_obj) { | |
if(!funcs_array.length) return initial_obj | |
return funcs_array[0](initial_obj).map(ecuder(funcs_array.slice(1))) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment