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.

Revisions

  1. sphilee created this gist May 5, 2018.
    12 changes: 12 additions & 0 deletions Dominator.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    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;
    }