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 | f1f5f74ad3c9b66cf60b5e86b5fc12afe52a448b (patch) | |
tree | b0012455948af3da83a9c2328d014c87189b5f8b | |
parent | 65e0b32a7e546136672837aba6acc8f9b1b53be7 (diff) | |
download | prosody-f1f5f74ad3c9b66cf60b5e86b5fc12afe52a448b.tar.gz prosody-f1f5f74ad3c9b66cf60b5e86b5fc12afe52a448b.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)]; |