loading...

re: Daily Challenge #220 - What Dominates Your Array? VIEW POST

FULL DISCUSSION
 

A solution in JavaScript:

const dominator = arr => {
  const indexes = {};

  for (let x = 0; x < arr.length; x++) {
    indexes[arr[x]] = indexes[arr[x]] ? indexes[arr[x]] + 1: 1;
    if (indexes[arr[x]] > arr.length / 2) return arr[x];
  }

  return -1;
}
code of conduct - report abuse