Last active
January 28, 2017 09:17
-
-
Save scazzy/47f351f5820bfe7b4266a6259edcc190 to your computer and use it in GitHub Desktop.
Nested array flatten method
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
let flattenedArray = []; | |
const flattn = (arr) => { | |
for(let i in arr) { | |
if(typeof arr[i] === 'object' && arr[i].length) { | |
flattn(arr[i]); | |
} else { | |
flattenedArray.push(arr[i]); | |
} | |
} | |
return flattenedArray; | |
}; | |
export default flattn; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment