Skip to content

Instantly share code, notes, and snippets.

@srkama
Created March 14, 2016 04:17
Show Gist options
  • Save srkama/37f71cc5b72adeb8d9a1 to your computer and use it in GitHub Desktop.
Save srkama/37f71cc5b72adeb8d9a1 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. Return the rest of the array, otherwise return an empty array.
function drop(arr, func) {
for(i=0;i<=arr.length;i++) {
if (func(arr[i])) {
return arr.slice(i);
}
}
return [];
}
drop([1, 2, 3], function(n) {return n < 3; });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment