From 1d72ec8b14b43ed8a1394dc8623054d508b95f32 Mon Sep 17 00:00:00 2001 From: NetMan <13informatyka14@gmail.com> Date: Fri, 5 Jan 2024 21:33:43 +0100 Subject: [PATCH] Passed fifth and sixth test from exercise 04 --- 04_removeFromArray/removeFromArray.js | 4 +--- 04_removeFromArray/removeFromArray.spec.js | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/04_removeFromArray/removeFromArray.js b/04_removeFromArray/removeFromArray.js index 269fb51..5d7d6de 100644 --- a/04_removeFromArray/removeFromArray.js +++ b/04_removeFromArray/removeFromArray.js @@ -3,7 +3,7 @@ const removeFromArray = function(array, ...remove) { let findIndexElement = array.findIndex(x => x == element); if (findIndexElement >= 0) { let saveArray = []; - for (let i = 0; i < array.length - findIndexElement; i++) { + for (let i = 0, arrayLength = array.length; i < arrayLength - findIndexElement - 1; i++) { saveArray.push(array.pop()); } array.pop(); @@ -15,7 +15,5 @@ const removeFromArray = function(array, ...remove) { return array; }; -removeFromArray([1, 2, 3, 4], 7, 2); - // Do not edit below this line module.exports = removeFromArray; diff --git a/04_removeFromArray/removeFromArray.spec.js b/04_removeFromArray/removeFromArray.spec.js index 0574d85..745a20f 100644 --- a/04_removeFromArray/removeFromArray.spec.js +++ b/04_removeFromArray/removeFromArray.spec.js @@ -13,10 +13,10 @@ describe('removeFromArray', () => { test('ignores non present values, but still works', () => { expect(removeFromArray([1, 2, 3, 4], 7, 2)).toEqual([1, 3, 4]); }); - test.skip('can remove all values', () => { + test('can remove all values', () => { expect(removeFromArray([1, 2, 3, 4], 1, 2, 3, 4)).toEqual([]); }); - test.skip('works with strings', () => { + test('works with strings', () => { expect(removeFromArray(["hey", 2, 3, "ho"], "hey", 3)).toEqual([2, "ho"]); }); test.skip('only removes same type', () => {