Created
December 20, 2017 05:48
-
-
Save barrars/3e1b04b84d5e7f95f0c4da2e514d12e9 to your computer and use it in GitHub Desktop.
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
const test1 = [ | |
[1, 2, 3, '4'], | |
[false, [1, 2], '6'] | |
], | |
test2 = [ | |
[ | |
[1, 78], | |
[false, 'true'], | |
[45, 'foo'] | |
], | |
[3, 5] | |
] | |
arr = test2 | |
function ea4(arr) { | |
var addem = [] | |
run(arr) | |
function run(arr) { | |
arr.forEach(element => { | |
console.log('ELEMENT = ' + element) | |
console.log(element) | |
if (Array.isArray(element)) { | |
console.log('returning') | |
return run(element); | |
} | |
if (Number.isInteger(element)) { | |
console.log(element) | |
console.log('this ' + element + ' is ' + Number.isInteger(element)) | |
addem.push(element) | |
console.log('add array now = ') | |
console.log(addem) | |
} else { | |
console.log(element + ' will not be added ') | |
return | |
} | |
}); | |
} | |
console.log(addem) | |
result = addem.reduce(function (a, b) { | |
return a + b; | |
}) | |
console.log('total = ' + result) | |
} | |
ea4(arr); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment