Last active
June 8, 2023 09:16
-
-
Save romanbsd/7d6f1781cc1e523e81afa4d2aa21818f to your computer and use it in GitHub Desktop.
flatten.js
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
export default function flattenArray(arr) { | |
return arr.reduce(function (flatArray, element) { | |
if (Array.isArray(element)) { | |
return flatArray.concat(flattenArray(element)); | |
} else { | |
return flatArray.concat(element); | |
} | |
}, []); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment