Skip to content

Instantly share code, notes, and snippets.

@Guseyn Guseyn/solution.js
Created Mar 25, 2019

Embed
What would you like to do?
theorem.applytojob.com solution
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
You can’t perform that action at this time.