Return the remaining elements of an array after chopping off n elements from the head.
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.
.slice()
allows to get only what you want from an array.
If you want the tail of a snake remove the head first. The .splice()
method changes the content of an array by removing existing elements and/or adding new elements. This can be handy. Get an array, remove the first part and return the remaining.
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);
function slasher(arr, howMany) {
//Return string after the amount chopped off.
return arr.slice(howMany);
}
If you found this page useful, you can give thanks by copying and pasting this on the main chat: Thanks @clint74 @Rafase282 @M-Bowe for your help with Algorithm: Slasher Flick
NOTE: Please add your username only if you have added any relevant main contents to the wiki page. (Please don't remove any existing usernames.)
,,, ,,,
;" ^; ;' ",
; s$$$$$$$s ;
, ss$$$$$$$$$$s ,'
;s$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$
$$$$P""Y$$$Y""W$$$$$ -{ Happy Camping! }
$$$$ p"$$$"q $$$$$
$$$$ .$$$$$. $$$$
$$DcaU$$$$$$$$$$
"Y$$$"*"$$$Y"
"$b.$$"