# HG changeset patch # User Matthew Wild # Date 1323234295 0 # Node ID 1c8d2c0d02db017cfbbe22506b1318ea3d5d9a2d # Parent 7f51186ed28b2f5c4373c3765a1c3aea6bb5e091 util.array: Add pluck() method to pick a given property from each item diff -r 7f51186ed28b -r 1c8d2c0d02db util/array.lua --- a/util/array.lua Wed Dec 07 04:57:51 2011 +0000 +++ b/util/array.lua Wed Dec 07 05:04:55 2011 +0000 @@ -60,6 +60,13 @@ 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)];