Skip to content

Instantly share code, notes, and snippets.

@bcrescimanno
Created October 4, 2013 18:18
Show Gist options
  • Save bcrescimanno/6830270 to your computer and use it in GitHub Desktop.
Save bcrescimanno/6830270 to your computer and use it in GitHub Desktop.
"Typical" solution for You Can't JavaScript under pressure Step 5
function monkey(arr) {
var len = arr.length,
cur,
finalVal = 0,
i;
for (i = 0; i < len; i++) {
cur = arr[i];
if (cur instanceof Array) {
finalVal += monkey(cur);
} else if (typeof cur === 'number') {
finalVal += cur;
}
}
return finalVal;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment