In this challenge I have to 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.
Following links are given as a clue:
This challenge makes use of both the above JavaScript methods.
The slice() method has already been discussed in chunky Monkey challenge. Here is the link to the post.
CHUNKY MONKEY
The splice method is new one, you can go through it on MDN javascript documentation here.
As for my solution to the problem, It took me few permutation and combination before arriving on the solution.
My solution is as follows.
If you have any suggestion, please let me know by commenting below the post.
This challenge makes use of both the above JavaScript methods.
The slice() method has already been discussed in chunky Monkey challenge. Here is the link to the post.
CHUNKY MONKEY
The splice method is new one, you can go through it on MDN javascript documentation here.
As for my solution to the problem, It took me few permutation and combination before arriving on the solution.
My solution is as follows.
function slasher(arr, howMany) {
var i = arr.slice(0,arr.length);
var x = arr.splice(howMany, i.length);
return x;
}
If you have any suggestion, please let me know by commenting below the post.
it may also like this
ReplyDeletefunction slasher(arr, howMany) {
// it doesn't always pay to be first
var x=arr.splice(howMany);
return x;
}
slasher([1, 2, 3], 2);