Skip to content

Commit

Permalink
Solve garageScript#47, Lesson 2: mostCommon - Takes in an array of nu…
Browse files Browse the repository at this point in the history
…mbers & find the most common number
  • Loading branch information
Alberto Lopez committed Oct 20, 2017
1 parent 52500f1 commit 3fa101e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 2 additions & 3 deletions solutions/mostCommon.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,5 @@ const common = (arr)=>{
const obj = buildMap(arr);
return maxVal(obj, Object.keys(obj));
}

console.log(common([2,3,3]));
console.log(common([1,1,1,2,2,2,2]));
//console.log(common([1,1,1,1,10,2,30,2,3,3,3]))
module.exports = common;
10 changes: 10 additions & 0 deletions test/mostCommon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const solution = require('../solutions/mostCommon.js');

const mostComm = (ar, result)=>{
if(solution(ar) == result){
console.log('Most common number');
}else{
console.log('Not most common number');
}
}
mostComm([2,21,2,3,3,3,1],3);

0 comments on commit 3fa101e

Please sign in to comment.