Skip to content

Commit

Permalink
another solution for problem llipio#16
Browse files Browse the repository at this point in the history
  • Loading branch information
rkalra247 committed Jun 9, 2017
1 parent c8a0e5e commit e55d563
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
27 changes: 26 additions & 1 deletion solutions/16.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@
//Manik Sachdeva: msach22
// Rahul Kalra
// should retirn true if the input has duplicates values and false if it doesn't

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

module.exports = {solution};

/*
//Manik Sachdeva: msach22
// should return true if the input array has duplicate values and false if it doesn't
const solution = (array) => {
Expand All @@ -15,3 +39,4 @@ const solution = (array) => {
module.exports = {
solution
};
*/
6 changes: 3 additions & 3 deletions test/16.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ let solution = require('../solutions/16').solution;
// solution = require('./yourSolution').solution;

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

0 comments on commit e55d563

Please sign in to comment.