Sorting a set of objects by a user's preference

前端 未结 10 1898
终归单人心
终归单人心 2020-12-13 16:09

Given a set of n objects in no specific order (n = 5 in this example):

{
    apple,
    orange,
    banana,
    cherry,
    cabbage
}

10条回答
  •  遥遥无期
    2020-12-13 16:15

    Well you could add weight to each item based on the users answers. So for instance in your example of

    banana      vs.      cabbage
          (no preference)
    

    When the user selects banana you add a plus one to the banana item. If they select cabbage you give plus one to cabbage and then if they select no preference then you can just give neither a plus one. Then you can sort the list from the largest value to the smallest.

提交回复
热议问题