Skip to content

Instantly share code, notes, and snippets.

@bartwttewaall
Last active December 16, 2021 10:31
Show Gist options
  • Save bartwttewaall/36a103164f37e9ba85cf56a8e8a1b5f7 to your computer and use it in GitHub Desktop.
Save bartwttewaall/36a103164f37e9ba85cf56a8e8a1b5f7 to your computer and use it in GitHub Desktop.
Array methods, akin to those from lodash / micro-dash
// create an array with indices 0..(amount-1)
export function fill(amount) {
return Array.from(Array(amount).keys());
}
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