0
我有一个这样的数组:嵌套一个给定的数组为儿童,根据病情
tweets = [
{
:user_id => 234567,
:username => "A",
:created_at => "2012-10-12 10:20:30"
},
{
:user_id => 234568,
:username => "B",
:created_at => "2012-10-12 10:20:34"
},
{
:user_id => 234569,
:username => "C",
:created_at => "2012-10-12 10:20:35"
},
{
:user_id => 234570,
:username => "D",
:created_at => "2012-10-12 10:20:40"
}
]
和另一个数组,像这样:
followers = [
{
:user_id => 234567,
:follower_ids => [234568, 56654]
},
{
:user_id => 234568,
:follower_ids => [234569, 454445]
},
{
:user_id => 234569,
:follower_ids => [234570, 56333]
},
{
:user_id => 234570,
:follower_ids => [45566, 61145]
}
]
我想窝成一个深层结构,其中一个被制造成另一个的孩子。为了使孩子们,要满足的条件是:
具有较大
created_at
比其他,和 包括在follower_ids名单在 该鸣叫的追随者阵列被认为是其user_id
任何其他鸣叫要个孩子
,并给定数据预期输出是这样的:
arranged_tweets = [
{
:user_id => 234567,
:username => "A",
:created_at => "2012-10-12 10:20:30",
:children => [
{
:user_id => 234568,
:username => "B",
:created_at => "2012-10-12 10:20:34",
:children => [
{
:user_id => 234569,
:username => "C",
:created_at => "2012-10-12 10:20:35",
:children => [
{
:user_id => 234570,
:username => "D",
:created_at => "2012-10-12 10:20:40"
}
]
}
]
}
]
}
]
你是怎么做的而不写任何代码? –
@ theTinMan ..你的意思是说,我试过的代码是什么? – rubyprince