Created
November 8, 2013 13:54
-
-
Save yegnold/7371340 to your computer and use it in GitHub Desktop.
For cole henley, not tested, probably errors all over the place, but this was my general approach
This file contains hidden or 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 add_all_integers(i) { | |
// i is an array that might contain arrrays, integers, strings, add all integers within it | |
var total = 0; | |
function add_iterate(item) { | |
for(var counter=0;counter<item.length;counter++) { | |
if(typeof item[counter] == 'object') { | |
add_iterate(item[counter]); | |
} else if(typeof item[counter] == 'number') { | |
total += item[counter]; | |
} | |
} | |
} | |
add_iterate(i); | |
return total; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
OK, surprisingly, running it in the console seems to suggest it is syntactically and functionally correct, wow, that's gotta be the first time ever for writing javascript - haha