Last active
December 16, 2021 10:31
-
-
Save bartwttewaall/36a103164f37e9ba85cf56a8e8a1b5f7 to your computer and use it in GitHub Desktop.
Array methods, akin to those from lodash / micro-dash
This file contains hidden or 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
// create an array with indices 0..(amount-1) | |
export function fill(amount) { | |
return Array.from(Array(amount).keys()); | |
} |
This file contains hidden or 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 function flatten(arr) { | |
return arr.reduce((flat, toFlatten) => | |
flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten) | |
, []); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment