Skip to content

Instantly share code, notes, and snippets.

@sphilee
Created May 5, 2018 02:25
Show Gist options
  • Select an option

  • Save sphilee/56a450a236342d12f5a429f1c17d9b34 to your computer and use it in GitHub Desktop.

Select an option

Save sphilee/56a450a236342d12f5a429f1c17d9b34 to your computer and use it in GitHub Desktop.
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const map = A.reduce((map,v,i)=>{
map[v] ? map[v].push(i) : map[v] = [i];
return map;
},{});
for(let item in map){
if(map[item].length > A.length/2) return map[item][0];
}
return -1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment