Last active
December 29, 2016 11:12
-
-
Save aethant/bcefb39aeed7c6f367678f4414e4e5fd to your computer and use it in GitHub Desktop.
Write some code, that will flatten an array of arbitrarily nested arrays of integers into a flat array of integers. e.g. [[1,2,[3]],4] -> [1,2,3,4]. Your solution should be a link to a gist on gist.github.com with your implementation. When writing this code, you can use any language you're comfortable with. The code must be well tested and docum…
This file contains 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 a = [ 23, 3, [ 5, 12, ], 11, ] | |
const b = [ [23, [233, 9, ], 11, ], 13, ] | |
const c = [ [ [ 222, 34, 55, 1, 7, ], 9, 1500, ], ] | |
const shallowify = arr => { | |
let results = [] | |
arr.forEach(arrEl => { | |
if (arrEl.constructor === Array) { | |
results = [...results, ...shallowify(arrEl), ] | |
} else { | |
results = [...results, arrEl, ] | |
} | |
}) | |
return results | |
} | |
console.log(shallowify([a, b, c])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment