Skip to content

Commit

Permalink
Merge pull request #30 from msach22/duplicates
Browse files Browse the repository at this point in the history
Duplicates #16
  • Loading branch information
msach22 authored Apr 27, 2017
2 parents 434e07d + 09e8aea commit ffa318c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
17 changes: 17 additions & 0 deletions solutions/16.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//msach22
// should return true if the input array has duplicate values and false if it doesn't

const hasDuplicates = (array) => {
let map = {};
for (let i = 0; i < array.length; i++) {
if (map[array[i]]) {
return true;
}
map[array[i]] = true;
};
return false;
}

module.exports = {
hasDuplicates
};
18 changes: 18 additions & 0 deletions test/16.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const expect = require('chai').expect;
const duplicates = require('../solutions/16');
const hasDuplicates = duplicates.hasDuplicates;

describe('check duplicates', () => {
it('should return true since array has duplicates', () => {
const array = [1,2,3,3,4];
expect(hasDuplicates(array)).to.be.true;
});
it('should return false because array does not have duplicates', () => {
const array = [1,2,3,4];
expect(hasDuplicates(array)).to.be.false;
});
it('should return false because array is empty', () => {
const array = [];
expect(hasDuplicates(array)).to.be.false;
});
});

0 comments on commit ffa318c

Please sign in to comment.