Make `array` an independent argument

This spares us from having to extract `array` from `args` and is more idiomatic (I think).
This commit is contained in:
Yossi Rise 2022-05-28 23:19:49 +03:00 committed by GitHub
parent db998d7279
commit b52b2ace26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 5 deletions

View File

@ -1,9 +1,7 @@
// we have 2 solutions here, an easier one and a more advanced one. // we have 2 solutions here, an easier one and a more advanced one.
// The easiest way to get an array of all of the arguments that are passed to a function // The easiest way to get an array of all of the arguments that are passed to a function
// is using the rest operator. If this is unfamiliar to you look it up! // is using the rest operator. If this is unfamiliar to you look it up!
const removeFromArray = function (...args) { const removeFromArray = function (array, ...args) {
// the very first item in our list of arguments is the array, we pull it out with args[0]
const array = args[0];
// create a new empty array // create a new empty array
const newArray = []; const newArray = [];
// use forEach to go through the array // use forEach to go through the array
@ -22,8 +20,7 @@ const removeFromArray = function (...args) {
// A simpler, but more advanced way to do it is to use the 'filter' function, // A simpler, but more advanced way to do it is to use the 'filter' function,
// which basically does what we did with the forEach above. // which basically does what we did with the forEach above.
// var removeFromArray = function(...args) { // var removeFromArray = function(array, ...args) {
// const array = args[0]
// return array.filter(val => !args.includes(val)) // return array.filter(val => !args.includes(val))
// } // }
// //