Skip to content

Instantly share code, notes, and snippets.

Created December 3, 2015 02:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/50564875c0d6a306b948 to your computer and use it in GitHub Desktop.
Save anonymous/50564875c0d6a306b948 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/nirajkrz 's solution for Bonfire: Drop it
// Bonfire: Drop it
// Author: @nirajkrz
// Challenge: http://www.freecodecamp.com/challenges/bonfire-drop-it
// Learn to Code at Free Code Camp (www.freecodecamp.com)
//Drop the elements of an array (first argument), starting from the front, until the predicate (second argument) returns true.
function drop(arr, func) {
// Drop them elements.
var lol = arr.length;
for (var i = 0; i < lol; i++) {
if (func(arr[0])) {
break;
} else {
arr.shift();
}
}
return arr;
}
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