-
Notifications
You must be signed in to change notification settings - Fork 24
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 #30 from msach22/duplicates
Duplicates #16
- Loading branch information
Showing
2 changed files
with
35 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,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 | ||
}; |
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,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; | ||
}); | ||
}); |