Skip to content

Instantly share code, notes, and snippets.

@octopuscabbage
Created August 2, 2015 00:50
Show Gist options
  • Save octopuscabbage/123a8d09d4425fe87fa0 to your computer and use it in GitHub Desktop.
Save octopuscabbage/123a8d09d4425fe87fa0 to your computer and use it in GitHub Desktop.
Heterogenous reduce sum.
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