Skip to content

Instantly share code, notes, and snippets.

@rickMcGavin
Created September 8, 2016 00:13
Show Gist options
  • Save rickMcGavin/78d109c2ef2d2a5a1c7eeee6f978b462 to your computer and use it in GitHub Desktop.
Save rickMcGavin/78d109c2ef2d2a5a1c7eeee6f978b462 to your computer and use it in GitHub Desktop.
// 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