From 804ba4a5f67d0b880a9625809c3a4c79c32e5741 Mon Sep 17 00:00:00 2001 From: drsoper Date: Mon, 8 May 2017 17:17:41 -0700 Subject: [PATCH] solves issue 34 with test --- solutions/34.js | 15 +++++++++++++++ test/34.js | 19 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 solutions/34.js create mode 100644 test/34.js diff --git a/solutions/34.js b/solutions/34.js new file mode 100644 index 0000000..1e8382c --- /dev/null +++ b/solutions/34.js @@ -0,0 +1,15 @@ +//Daniel +//Number of repeating elements in an array + +const solution = (arr, k) => { + let total = 0; + for (i=0; i < arr.length; i++) { + if (arr[i] === k){ + total++; + } + } + return total; + }; + module.exports = { + solution +}; diff --git a/test/34.js b/test/34.js new file mode 100644 index 0000000..8940b77 --- /dev/null +++ b/test/34.js @@ -0,0 +1,19 @@ +const expect = require('chai').expect; +const solution = require('../solutions/34.js').solution; +// solution = require('../yourSolution').solution; + +describe('return number of repeating elements', () => { + it('simple case', () => { + expect(solution([2],2)).to.equal(1); + }); + it('hard case', () => { + expect(solution([3,2],1)).to.equal(0); + }); + it('harder case', () => { + expect(solution([3,2,3,2],2)).to.equal(2); + }) + it('hardest case', () => { + expect(solution([5,5,3,2,3,2,5,5],5)).to.equal(4); + }); +}); +