Created
November 18, 2015 16:23
-
-
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.
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) { | |
// 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