function - javascript parameters passing -


this code have been given. looked around , don't quite understand.

this question function destroyer accepts 1 parameter array when being call 3 parameters sent array , 2 integers.

how can access 2 integer parameters in function if haven't been passed? there in javascript allow this?

         function destroyer(arr) {          // remove value;          return arr;          }          destroyer([1, 2, 3, 1, 2, 3], 2, 3); 

you can use arguments variable in function list of passed arguments.

// es5  function destroyer(arr) {      var pieces = array.prototype.splice.call(arguments, 1);      var = 0;        while (arr[i]) {          -1 === pieces.indexof(arr[i]) ? i++ : arr.splice(i, 1);      }        return arr;  }    // es6  function destroyer2(arr, ...pieces) {      var = 0;        while (arr[i]) {          -1 === pieces.indexof(arr[i]) ? i++ : arr.splice(i, 1);      }        return arr;  }    console.log(json.stringify(destroyer([1, 2, 3, 1, 2, 3], 3, 1)));  console.log(json.stringify(destroyer2([1, 2, 3, 1, 2, 3], 2, 3)));


Comments