Skip to content

Instantly share code, notes, and snippets.

@wmakeev
Created February 20, 2022 09:34
Show Gist options
  • Save wmakeev/16eb0ca5e066ea3f8fdc290818e82c66 to your computer and use it in GitHub Desktop.
Save wmakeev/16eb0ca5e066ea3f8fdc290818e82c66 to your computer and use it in GitHub Desktop.
[Array drop] #tools #array #helper
/**
* @type {<T>(arr: T[], predicate: (item: T) => boolean) => T[]}
*/
const dropHeadAfter = (arr, predicate) => {
if (arr.length === 0) return []
for (let i = 0, len = arr.length; i < len; i++) {
if (!predicate(arr[i])) {
return arr.slice(i)
}
}
return []
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment