util.array: Add pluck() method to pick a given property from each item

This commit is contained in:
Matthew Wild 2011-12-07 05:04:55 +00:00
parent 65e0b32a7e
commit f1f5f74ad3

View file

@ -60,6 +60,13 @@ function array_base.sort(outa, ina, ...)
return outa;
end
function array_base.pluck(outa, ina, key)
for i=1,#ina do
outa[i] = ina[i][key];
end
return outa;
end
--- These methods only mutate
function array_methods:random()
return self[math.random(1,#self)];