From b8913a605eab3bcf1538af5c8d8d1193e77fd6c6 Mon Sep 17 00:00:00 2001 From: Don Date: Thu, 23 Jun 2022 15:26:25 -0400 Subject: [PATCH] Merge branch 'master' of https://github.com/nard0g/javascript-exercises --- 04_removeFromArray/removeFromArray.js | 15 +++++++++++++-- 04_removeFromArray/removeFromArray.spec.js | 12 ++++++------ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/04_removeFromArray/removeFromArray.js b/04_removeFromArray/removeFromArray.js index 1818318..ba30120 100644 --- a/04_removeFromArray/removeFromArray.js +++ b/04_removeFromArray/removeFromArray.js @@ -1,6 +1,17 @@ -const removeFromArray = function() { - // +const removeFromArray = function(...args) { + let origArray = args[0] + let newArr = [] + origArray.forEach((arg) => { + if (!args.includes(arg)) { + newArr.push(arg) + } + }) + + return newArr }; // Do not edit below this line module.exports = removeFromArray; + + +removeFromArray([1, 2, 3, 4], 3) \ No newline at end of file diff --git a/04_removeFromArray/removeFromArray.spec.js b/04_removeFromArray/removeFromArray.spec.js index 21f34cf..c17239a 100644 --- a/04_removeFromArray/removeFromArray.spec.js +++ b/04_removeFromArray/removeFromArray.spec.js @@ -4,22 +4,22 @@ describe('removeFromArray', () => { test('removes a single value', () => { expect(removeFromArray([1, 2, 3, 4], 3)).toEqual([1, 2, 4]); }); - test.skip('removes multiple values', () => { + test('removes multiple values', () => { expect(removeFromArray([1, 2, 3, 4], 3, 2)).toEqual([1, 4]); }); - test.skip('ignores non present values', () => { + test('ignores non present values', () => { expect(removeFromArray([1, 2, 3, 4], 7, "tacos")).toEqual([1, 2, 3, 4]); }); - test.skip('ignores non present values, but still works', () => { + 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', () => { + test('only removes same type', () => { expect(removeFromArray([1, 2, 3], "1", 3)).toEqual([1, 2]); }); });