Skip to content

Commit

Permalink
solution and test for llipio#16
Browse files Browse the repository at this point in the history
  • Loading branch information
msach22 committed Apr 26, 2017
1 parent 434e07d commit 6b00914
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
19 changes: 19 additions & 0 deletions solutions/16.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//msach22
// should return true if the input array has duplicant element values

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;
}

array = [1,2,3];

module.exports = {
hasDuplicates
};
21 changes: 21 additions & 0 deletions test/16.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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];
const expected = true;
expect(hasDuplicates(array)).eql(expected);
});
it('should return false because array does not have duplicates', () => {
const array = [1,2,3,4];
const expected = false;
expect(hasDuplicates(array)).eql(expected);
});
it('should return false because array is empty', () => {
const array = [];
const expected = false;
expect(hasDuplicates(array)).eql(expected);
});
});

0 comments on commit 6b00914

Please sign in to comment.