How to prevent automatic sort of Object numeric property?

后端 未结 10 1257
醉酒成梦
醉酒成梦 2020-12-03 20:57

Why I met this problem: I tried to solve an algorithm problem and I need to return the number which appeared most of the times in an array. Like [5,4,3,2,1,1] should return

10条回答
  •  自闭症患者
    2020-12-03 21:24

    instead of generating an object like {5: 2, 2: 2, 1: 1}

    generate an array to the effect of

    [
       {key: 5, val: 2},
       {key: 2, val: 2},
       {key: 1, val: 1}
    ]
    

    or... keep track of the sort order in a separate value or key

提交回复
热议问题