我有一个问题,我试图计算有多少孩子的年龄(作为关键)如下,但我们希望得到基于孩子的大孩子组(在这种情况下是 4 和 2)> = 4 个孩子组我想获得可以组成一个 bigkids 组的最大年龄数。
问题我怎样才能得到最大年龄小于/等于 4 个孩子的新创建组的年龄?
所以这是我们输入的内容
max_bigest_kids_in_group = 4
kids object = {
//age 0 have 7 kids
'0' : 7
//age 1 have 3 kids
'1' : 3
//age 2 have 2 kids
'2' : 2
//age 4 have 1 kids
'4' : 1
//lets say there is no age 3 or 5,6 and so on.
}
这是我目前在psudo中尝试过和目前所做的
try biggest next biggest
('4' = 1) + ('2' = 2) (oke becouse 1+2 is 3 >= 4) save array [4 and 2]
try biggest next biggest next biggest
('4' = 1) + ('2' = 2) + ('1' = 3) (not oke becouse 1+2+3 is 6 >= 4) stop becouse its more then x = 4
get array [4 and 2]
// expected result is {'4','2'} or ['4','2'] so if max_bigest_kids_in_group = 6 then it will be ['4','2','1']
我们怎样才能得到预期的结果?在javascript中
附言。对不起,如果标题不是那么准确,如果有任何建议,请评论或编辑。