Skip to content

Commit

Permalink
Merge pull request llipio#46 from dsope05/dan1
Browse files Browse the repository at this point in the history
solves issue 34 with test
  • Loading branch information
msach22 authored May 9, 2017
2 parents 2ddc3b1 + 804ba4a commit 3152c8d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
15 changes: 15 additions & 0 deletions solutions/34.js
Original file line number Diff line number Diff line change
@@ -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
};
19 changes: 19 additions & 0 deletions test/34.js
Original file line number Diff line number Diff line change
@@ -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);
});
});

0 comments on commit 3152c8d

Please sign in to comment.