-
-
Save nirajkrz/86fd1845050819e20a6d to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/nirajkrz 's solution for Bonfire: Drop it
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
// 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