Last active
April 5, 2016 06:46
-
-
Save mmloveaa/31463ab39ab41cccf52cccf41ee5c54a to your computer and use it in GitHub Desktop.
4-4 Q11 Slasher Flick
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
| Slasher Flick | |
| Return the remaining elements of an array after chopping off n elements from the head. | |
| The head means the beginning of the array, or the zeroth index. | |
| Remember to use Read-Search-Ask if you get stuck. Write your own code. | |
| using splice | |
| function slasher(arr, howMany) { | |
| // it doesn't always pay to be first | |
| arr.splice(0,howMany); | |
| return arr; | |
| } | |
| or using slice | |
| function slasher(arr, howMany) { | |
| return arr.slice(howMany); | |
| } | |
| slasher([1, 2, 3], 2); | |
| slasher([1, 2, 3], 2) should return [3]. | |
| slasher([1, 2, 3], 0) should return [1, 2, 3]. | |
| slasher([1, 2, 3], 9) should return []. | |
| slasher([1, 2, 3], 4) should return []. | |
| slasher(["burgers", "fries", "shake"], 1) should return ["fries", "shake"]. | |
| slasher([1, 2, "chicken", 3, "potatoes", "cheese", 4], 5) should return ["cheese", 4]. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment