Skip to content

Commit

Permalink
Merge pull request #71 from seemcat/mc5
Browse files Browse the repository at this point in the history
Test & Solution for #34
  • Loading branch information
dsope05 authored Jun 13, 2017
2 parents e883ddf + 746e72a commit 8ddd9e6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
26 changes: 22 additions & 4 deletions solutions/34.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Daniel
// Number of repeating elements in an array

const solution = (arr, k) => {
let total = 0;
for (i=0; i < arr.length; i++) {
Expand All @@ -9,7 +8,26 @@ const solution = (arr, k) => {
}
}
return total;
};
module.exports = {
solution,
};

// Maricris Bonzo
const solution1 = (array, num) => {
let i = 0;
let numOfTimes = 0;

while (i < array.length){
if (array[i] === num){
numOfTimes = numOfTimes + 1;
i++;
} else {
i++;
}
}
return numOfTimes;
};

module.exports = {
solution,
solution1
};

14 changes: 14 additions & 0 deletions test/34.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const expect = require('chai').expect;
const solution = require('../solutions/34.js').solution;
const solution1 = require('../solutions/34.js').solution1;
// solution = require('../yourSolution').solution;

describe('return number of repeating elements', () => {
Expand All @@ -15,5 +16,18 @@ describe('return number of repeating elements', () => {
it('hardest case', () => {
expect(solution([5, 5, 3, 2, 3, 2, 5, 5], 5)).to.equal(4);
});
it('simple case', () => {
expect(solution1([2],2)).to.equal(1);
});
it('hard case', () => {
expect(solution1([3,2],1)).to.equal(0);
});
it('harder case', () => {
expect(solution1([3,2,3,2],2)).to.equal(2);
})
it('hardest case', () => {
expect(solution1([5,5,3,2,3,2,5,5],5)).to.equal(4);
});

});

0 comments on commit 8ddd9e6

Please sign in to comment.