-
Notifications
You must be signed in to change notification settings - Fork 0
Algorithm Slasher Flick
🚩 Remember to use Read-Search-Ask
if you get stuck. Try to pair program 👥 and write your own code 📝
For example: slasher([1, 2, 3], 2);
must return [3].
- We need only the remaining part of an array, so we can just remove what we don't.
try to solve the problem now
-
splice()
function can be used.
try to solve the problem now
-
slice()
function can be used.
try to solve the problem now
Solution ahead!
function slasher(arr, howMany) {
// remove the head
arr.splice(0, howMany);
// return the remaining or the tail
return arr;
}
slasher([1, 2, 3], 2);
🚀 Run Code
- This solution uses the
splice()
function. - First argument, arr is the array to be modified.
- Second argument, howMany is the number of elements to be removed starting with arr[0].
- Modify the array with
splice()
and return it.
function slasher(arr, howMany) {
// Return string after the amount chopped off.
return arr.slice(howMany);
}
🚀 Run Code
- This solution uses the
slice()
function. - The argument howMany is the number of elements to be removed starting with arr[0].
- Modify the array with
slice()
and return it.
If you found this page useful, you may say thanks to the contributors by copying and pasting the following line in the main chat:
Thanks @clint74 @Rafase282 @M-Bowe for your help with Algorithm: Slasher Flick
⚠️ DO NOT add solutions that are similar to any existing solutions. If you think it is similar but better, then try to merge (or replace) the existing similar solution.- Add an explanation of your solution.
- Categorize the solution in one of the following categories — Basic, Intermediate and Advanced. 🚥
- Please add your username only if you have added any relevant main contents. (:warning: DO NOT remove any existing usernames)
See 👉
Wiki Challenge Solution Template
for reference.
Learn to code and help nonprofits. Join our open source community in 15 seconds at http://freecodecamp.com
Follow our Medium blog
Follow Quincy on Quora
Follow us on Twitter
Like us on Facebook
And be sure to click the "Star" button in the upper right of this page.
New to Free Code Camp?
JS Concepts
JS Language Reference
- arguments
- Array.prototype.filter
- Array.prototype.indexOf
- Array.prototype.map
- Array.prototype.pop
- Array.prototype.push
- Array.prototype.shift
- Array.prototype.slice
- Array.prototype.some
- Array.prototype.toString
- Boolean
- for loop
- for..in loop
- for..of loop
- String.prototype.split
- String.prototype.toLowerCase
- String.prototype.toUpperCase
- undefined
Other Links