Created
March 25, 2019 16:32
-
-
Save Guseyn/3e3c5413eba8215cd7d3c89b2ec0b5ea to your computer and use it in GitHub Desktop.
theorem.applytojob.com solution
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 assert = require('assert') | |
function flattenArray (nestedArray, resArray = []) { | |
for (let i = 0; i < nestedArray.length; i++) { | |
if (Array.isArray(nestedArray[i])) { | |
flattenArray(nestedArray[i], resArray) | |
} else { | |
resArray.push(nestedArray[i]) | |
} | |
} | |
return resArray | |
} | |
assert.deepStrictEqual(flattenArray([[1, 2, [3]], 4]), [1, 2, 3, 4]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment