Created
March 14, 2016 04:17
-
-
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.
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
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