From 4a267cd05acd2fb9afe1d2a8fafcfdcd57d91bda Mon Sep 17 00:00:00 2001 From: Rajas Shah Date: Wed, 28 Sep 2022 17:48:32 -0600 Subject: [PATCH] Change function arguments in removeFromArray As per current definition, within the forEach loop, the array itself (being an element of args) is checked for includes('item'), leading to one additional comparison. However, it doesn't lead to error as item will never be the array itself. By splitting the arguments here, the additional comparison is avoided. --- removeFromArray/removeFromArray.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/removeFromArray/removeFromArray.js b/removeFromArray/removeFromArray.js index 3a68b8a..84a03dc 100644 --- a/removeFromArray/removeFromArray.js +++ b/removeFromArray/removeFromArray.js @@ -1,9 +1,9 @@ // 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) { +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]; + // const array = args[0]; // create a new empty array const newArray = []; // use forEach to go through the array