TASK: Drop the elements of an array (first argument), starting from the front, until the predicate (second argument) returns true.
This one passes the test, but I feel like I cheated, since it does not, strictly speaking, do what was requested.
function drop(arr, func) { return arr.filter(func); } drop([1, 2, 3], function(n) {return n < 3; });
I tried hard to write a recursive that would actually better fulfil the task, but I couldn’t make it work. This is an alternative that comes closer to doing what is asked:
function drop(arr, func) { var solution = []; for (var i=0; i<arr.length; i++) { if (func(arr[i])) {solution.push(arr[i]);} } return solution; } drop([1, 2, 3], function(n) {return n < 3; });