Skip to content

Instantly share code, notes, and snippets.

@henrik1
Created June 2, 2022 18:12
Show Gist options
  • Select an option

  • Save henrik1/d310668683a203e8d72490e39d9f6391 to your computer and use it in GitHub Desktop.

Select an option

Save henrik1/d310668683a203e8d72490e39d9f6391 to your computer and use it in GitHub Desktop.
Drops elements from a list until some condition is met
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