From f1f5f74ad3c9b66cf60b5e86b5fc12afe52a448b Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 7 Dec 2011 05:04:55 +0000 Subject: util.array: Add pluck() method to pick a given property from each item --- util/array.lua | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'util') diff --git a/util/array.lua b/util/array.lua index 5dbd3037..cf586214 100644 --- a/util/array.lua +++ b/util/array.lua @@ -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)]; -- cgit v1.2.3