In this challenge we are provided with an initial array i.e the first argument in the destroyer function It is followed by one or more arguments. We have to remove all elements from the first array that are of the same value as are these arguments.
Following clues are given for reference:
To be frank I have to sweat out a lot with this algorithm, First it took me a while to get my head around the Arguments Objects. I used Read-Search-Ask technique to get more clues and finally after a lot of efforts i got to the following solution.
My solution for the problem is given below:
To be frank I have to sweat out a lot with this algorithm, First it took me a while to get my head around the Arguments Objects. I used Read-Search-Ask technique to get more clues and finally after a lot of efforts i got to the following solution.
My solution for the problem is given below:
function destroyer(arr) {
arr1 = []; //create a new array of arguments
for ( i = 1; i < arguments.length; i++){
j = arguments[i];
arr1.push(j);
}
function checker(value) { // returns items not in index
return arr1.indexOf(value) === -1;
}
return arr.filter(checker); //Filter the items given by
//checker func
}
No comments:
Post a Comment