给出:
data = [
{"id"=>nil, "votable_id"=>1150, "user_ids"=>"1120,1119,1118,1117,1116,1115,1114,1113,1112,1111,1110,1109,1108,1107"},
{"id"=>nil, "votable_id"=>1151, "user_ids"=>"1120,1119,1118,1117,1116,1115,1114,1113,1112,1111,1110,1109,1108,1107"}
]
我希望返回字符串g["user_ids"]
中所有整数的唯一表示的数组,该数组表示为g
元素的所有散列data
;即,>
["1120", "1119", "1118", "1117", "1116", "1115", "1114",
"1113", "1112", "1111", "1110", "1109", "1108", "1107"]
给出:data = [{“ id” => nil,“ votable_id” => 1150,“ user_ids” =>“ 1120,1119,1118,1117,1116,1115,1114,1113,1112,1111,1110, 1109,1108,1107“},{” id“ => nil,” votable_id“ => 1151,” user_ids“ => ...
如果使用Rails,请尝试以下操作:
要获得唯一的ID:
String#split