Created
February 20, 2022 09:34
-
-
Save wmakeev/16eb0ca5e066ea3f8fdc290818e82c66 to your computer and use it in GitHub Desktop.
[Array drop] #tools #array #helper
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
/** | |
* @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