Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Guseyn
Created March 25, 2019 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Guseyn/3e3c5413eba8215cd7d3c89b2ec0b5ea to your computer and use it in GitHub Desktop.
Save Guseyn/3e3c5413eba8215cd7d3c89b2ec0b5ea to your computer and use it in GitHub Desktop.
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