Created
June 2, 2022 18:12
-
-
Save henrik1/d310668683a203e8d72490e39d9f6391 to your computer and use it in GitHub Desktop.
Drops elements from a list until some condition is met
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
| const dropWhile = (pred, list) => { | |
| let index = 0; | |
| list.every(elem => { | |
| index++; | |
| return pred(elem); | |
| }); | |
| return list.slice(index-1); | |
| } | |
| dropWhile(val => (val < 5), [1,2,3,4,5,6,7]); // = [5,6,7] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment