synapsecns/sanguine

View on GitHub
packages/explorer-ui/utils/math/statistics.ts

Summary

Maintainability
A
25 mins
Test Coverage
export const mode = (arr) => {
  const mode = {}
  let max = 0
  let count = 0

  for (let i = 0; i < arr.length; i++) {
    const item = arr[i]

    if (mode[item]) {
      mode[item]++
    } else {
      mode[item] = 1
    }

    if (count < mode[item]) {
      max = item
      count = mode[item]
    }
  }

  return max
}