diff options
author | Kim Alvefur <zash@zash.se> | 2017-03-31 17:29:08 +0200 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2017-03-31 17:29:08 +0200 |
commit | 72018f7be717db4e99cf175d46cbc9d97c6249aa (patch) | |
tree | 3558efe7b236bd05a8f2f0148df8e6f9d2275d6b /util | |
parent | 7b5aa05b026aadab237d9d101a9f455ea070e5e8 (diff) | |
download | prosody-72018f7be717db4e99cf175d46cbc9d97c6249aa.tar.gz prosody-72018f7be717db4e99cf175d46cbc9d97c6249aa.zip |
util.array: Add method for filtering out duplicate values
Diffstat (limited to 'util')
-rw-r--r-- | util/array.lua | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/util/array.lua b/util/array.lua index 05fa97ca..150b4355 100644 --- a/util/array.lua +++ b/util/array.lua @@ -92,6 +92,18 @@ function array_base.sort(outa, ina, ...) return outa; end +function array_base.unique(outa, ina) + local seen = {}; + return array_base.filter(outa, ina, function (item) + if seen[item] then + return false; + else + seen[item] = true; + return true; + end + end); +end + function array_base.pluck(outa, ina, key) for i = 1, #ina do outa[i] = ina[i][key]; |