Skip to content

Commit

Permalink
llipio#16 solutions and test
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinX13 committed Jun 7, 2017
1 parent c8a0e5e commit eef599d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
8 changes: 4 additions & 4 deletions test/16.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
const expect = require('chai').expect;
let solution = require('../solutions/16').solution;
// solution = require('./yourSolution').solution;
solution = require('../yourSolution').solution;

describe('check duplicates', () => {
it('should return true since array has duplicates', () => {
it('should return true since array has duplicates [1,2,3,3,4] ', () => {
const array = [1,2,3,3,4];
expect(solution(array)).to.be.true;
});
it('should return false because array does not have duplicates', () => {
it('should return false because array does not have duplicates [1,2,3,4]', () => {
const array = [1,2,3,4];
expect(solution(array)).to.be.false;
});
it('should return false because array is empty', () => {
it('should return false because array is emptyi []', () => {
const array = [];
expect(solution(array)).to.be.false;
});
Expand Down
17 changes: 16 additions & 1 deletion yourSolution.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
// Name
// Problem Description

const solution = () => {
const solution = (arr) => {
let obj = {};
for(let i = 0; i < arr.length; i++){
if(!obj[arr[i]]){
obj[arr[i]] = 1;
}
else{
obj[arr[i]]++;
}
}
for(let key in obj){
if(obj[key] > 1){
return true;
}
}
return false;
};

module.exports = {
Expand Down

0 comments on commit eef599d

Please sign in to comment.