Created
August 2, 2015 00:50
-
-
Save octopuscabbage/123a8d09d4425fe87fa0 to your computer and use it in GitHub Desktop.
Heterogenous reduce sum.
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
function heterogenous_sum_fold(prev, cur, I, a){ | |
if( Object.prototype.toString.call( someVar ) === '[object Array]') { //if it's an array | |
return prev +cur.reduce(heterogeneous_sum_fold); | |
//apply this function recursively. | |
} | |
return prev + cur; // probably everything else. Might error. | |
} | |
Array.reduce(heterogeneous_sum_fold); //how to invoke |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment