diff --git a/solutions/33.js b/solutions/33.js new file mode 100644 index 0000000..6bfb2f4 --- /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]); + }) +});