From c505e7c1e311c725f44607c5a8150279ddd57984 Mon Sep 17 00:00:00 2001 From: seemcat Date: Tue, 6 Jun 2017 11:55:28 -0700 Subject: [PATCH 1/2] Test & Solution for #33 --- solutions/33.js | 21 +++++++++++++++++++++ test/33.js | 15 +++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 solutions/33.js create mode 100644 test/33.js diff --git a/solutions/33.js b/solutions/33.js new file mode 100644 index 0000000..67f66f3 --- /dev/null +++ b/solutions/33.js @@ -0,0 +1,21 @@ +// Maricris Bonzo: @seemcat +// create a function that takes in an array and a number +// and returns an array without that number + +const solution = (arr, num) => { + let i = 0; + let newArr = [] + while (i < arr.length) { + if (num !== arr[i]) { + newArr.push(arr[i]); + i++; + } else { + i++; + } + } + return newArr; +}; + +module.exports = { + solution +}; diff --git a/test/33.js b/test/33.js new file mode 100644 index 0000000..46ec4a1 --- /dev/null +++ b/test/33.js @@ -0,0 +1,15 @@ +const expect = require('chai').expect; +let solution = require('../solutions/33').solution; +// solution = require('./yourSolution').solution; + +describe('array without a number', () => { + it('array [1,2,3,2,2,3] without 2 is [1,3,3]', () => { + expect(solution([1,2,3,2,2,3],2)).eql([1,3,3]); + }) + it('array [1,2,3,2,2,3] without 3 is [1,2,2,2]', () => { + expect(solution([1,2,3,2,2,3],3)).eql([1,2,2,2]); + }) + it('array [1,2,3,2,2,3] without 1 is [2,3,2,2,3]', () => { + expect(solution([1,2,3,2,2,3],1)).eql([2,3,2,2,3]); + }) +}); From 63f39a1ed38cf918c3957d01f6e8d913aa398079 Mon Sep 17 00:00:00 2001 From: seemcat Date: Thu, 15 Jun 2017 11:50:36 -0700 Subject: [PATCH 2/2] Added the missing semicolon. --- solutions/33.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solutions/33.js b/solutions/33.js index 67f66f3..6bfb2f4 100644 --- a/solutions/33.js +++ b/solutions/33.js @@ -4,7 +4,7 @@ const solution = (arr, num) => { let i = 0; - let newArr = [] + let newArr = []; while (i < arr.length) { if (num !== arr[i]) { newArr.push(arr[i]);