forked from llipio/algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request llipio#46 from dsope05/dan1
solves issue 34 with test
- Loading branch information
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
|