T
Size: a a a
T
RS
T
T
PG
Enum.group_by(
...,
&"#{Enum.at(&1, 2)}(#{Enum.at(&1, 3)})",
&Enum.take(&1,2)
)
T
Enum.group_by(
...,
&"#{Enum.at(&1, 2)}(#{Enum.at(&1, 3)})",
&Enum.take(&1,2)
)
RS
array = [
[1, "Мурзик", "кот", 3],
[2, "Серый", "кот", 3],
[3, "Серый 2", "кот", 3],
[4, "Аватар", "собака", 2],
[5, "Спасатель", "собака", 2],
[6, "Накорм", "хрюндель", 1]
]
map = {}
array.each do |row|
id = row.first
name = row[1]
animal = row[2]
count = row.last
key = "#{animal} (#{count})"
if map[key]
map[key] << [id, name]
else
map[key] = [[id, name]]
end
end
T
array = [
[1, "Мурзик", "кот", 3],
[2, "Серый", "кот", 3],
[3, "Серый 2", "кот", 3],
[4, "Аватар", "собака", 2],
[5, "Спасатель", "собака", 2],
[6, "Накорм", "хрюндель", 1]
]
map = {}
array.each do |row|
id = row.first
name = row[1]
animal = row[2]
count = row.last
key = "#{animal} (#{count})"
if map[key]
map[key] << [id, name]
else
map[key] = [[id, name]]
end
end
T
RS
RS
T
PG
T
RS
RS
ŹR
Enum.group_by(
[
[1, "Мурзик", "кот", 3],
[2, "Серый", "кот", 3],
[3, "Серый 2", "кот", 3],
[4, "Аватар", "собака", 2],
[5, "Спасатель", "собака", 2],
[6, "Накорм", "хрюндель", 1]
],
fn [_id, _name, type, type_id] -> "#{type} (#{type_id})" end,
fn [id, name, _type, _type_id] -> [id, name] end
)
T