From b52b2ace26af091cf805d69bb5607da0a9b585d5 Mon Sep 17 00:00:00 2001 From: Yossi Rise <66458823+yossirise@users.noreply.github.com> Date: Sat, 28 May 2022 23:19:49 +0300 Subject: [PATCH] Make `array` an independent argument This spares us from having to extract `array` from `args` and is more idiomatic (I think). --- removeFromArray/removeFromArray.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/removeFromArray/removeFromArray.js b/removeFromArray/removeFromArray.js index 3a68b8a..d6969e0 100644 --- a/removeFromArray/removeFromArray.js +++ b/removeFromArray/removeFromArray.js @@ -1,9 +1,7 @@ // 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 // is using the rest operator. If this is unfamiliar to you look it up! -const removeFromArray = function (...args) { - // the very first item in our list of arguments is the array, we pull it out with args[0] - const array = args[0]; +const removeFromArray = function (array, ...args) { // create a new empty array const newArray = []; // 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, // which basically does what we did with the forEach above. -// var removeFromArray = function(...args) { -// const array = args[0] +// var removeFromArray = function(array, ...args) { // return array.filter(val => !args.includes(val)) // } //