Skip to content

Instantly share code, notes, and snippets.

@musantro
Created November 18, 2015 16:23
Show Gist options
  • Save musantro/c3c556580494b55e903d to your computer and use it in GitHub Desktop.
Save musantro/c3c556580494b55e903d to your computer and use it in GitHub Desktop.
Drop the elements of an array (first argument), starting from the front, until the predicate (second argument) returns true.
function drop(arr, func) {
// Drop them elements.
var length = arr.length;
for(i=0;i<=length;i++){
if(func(arr[0])){
return arr;
}
console.log(arr);
arr.shift();
if(arr.length === 0){
return [];
}
}
}
drop([1, 2, 3, 4], function(n) {return n > 5; });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment