Algorithm slasher flick - ashish9342/FreeCodeCamp GitHub Wiki
🚩 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.