หา mode อันดับ 2 ใน array - Gaoey/exercises GitHub Wiki

example

const x = [1,2,2,2,3,4,5,5,5,5,6,6,6,6,6]
result = 5

js

const input = [1,2,2,2,3,3,3,3,4,4,4,4,6]

const temp = input.map((v,i)=>{
  if(v === input[i+1]) {
    return undefined
  }
  return input.filter(a => a == v)
}).filter(v => v !== undefined)

const x = temp.map(v=>{
  return {
    value: v[0],
    size: v.length
  }
})


const sortT = x.sort((a, b) => a.size - b.size)
const result = sortT[sortT.length-2].value