Created
September 8, 2016 00:13
-
-
Save rickMcGavin/78d109c2ef2d2a5a1c7eeee6f978b462 to your computer and use it in GitHub Desktop.
This file contains 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
// freecodecamp | |
// intermediate algorithm scripting | |
// drop it | |
// Drop the elements of an array (first argument), starting from the front, until the predicate (second argument) returns true. | |
// The second argument, func, is a function you'll use to test the first elements of the array to decide if you should drop it or not. | |
// Return the rest of the array, otherwise return an empty array. | |
function dropElements(arr, func) { | |
while (!func(arr[0])) | |
arr.shift(); | |
return arr; | |
} | |
console.log(dropElements([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