Skip to content

Instantly share code, notes, and snippets.

@SeeThruHead
Last active August 29, 2015 14:26
Show Gist options
  • Save SeeThruHead/173d1c95eeb9b21b68dd to your computer and use it in GitHub Desktop.
Save SeeThruHead/173d1c95eeb9b21b68dd to your computer and use it in GitHub Desktop.
function isInt(x) {
return (typeof x === 'number') && (x % 1 === 0);
}
function flatten(ar) {
return ar.reduce(function(prev, curr) {
return prev.concat((Array.isArray(curr) ? flatten(curr) : curr));
}, []);
}
function arraySum(i) {
return flatten(i).reduce(function(prev, curr) {
return isInt(curr) ? prev + curr : prev;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment