Last active
April 4, 2016 17:22
-
-
Save mmloveaa/2d121a394d83c02075069de2f14e7254 to your computer and use it in GitHub Desktop.
4-3 Drop it - freecodecamp
This file contains hidden or 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
| 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. | |
| Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code. | |
| Here are some helpful links: | |
| function drop(arr, func) { | |
| // Drop them elements. | |
| for (var i=0; i<arr.length; i++){ | |
| if (func(arr[i])){ | |
| return arr.slice(i); | |
| } | |
| } | |
| return []; | |
| } | |
| drop([0,1,0,1], function(n) {return n === 1; }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment