diff options
author | Matthew Wild <mwild1@gmail.com> | 2011-12-07 05:04:55 +0000 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2011-12-07 05:04:55 +0000 |
commit | 0572f1ef240e909b4e16feda8964e56cfb1aa982 (patch) | |
tree | b0012455948af3da83a9c2328d014c87189b5f8b | |
parent | 1ef4ed4ad00f546da835900daa15687613982b6b (diff) | |
download | prosody-0572f1ef240e909b4e16feda8964e56cfb1aa982.tar.gz prosody-0572f1ef240e909b4e16feda8964e56cfb1aa982.zip |
util.array: Add pluck() method to pick a given property from each item
-rw-r--r-- | util/array.lua | 7 |
1 files changed, 7 insertions, 0 deletions
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)]; |