mirror of
https://github.com/bjc/prosody.git
synced 2025-04-03 21:27:38 +03:00
util.array: Add method for filtering out duplicate values
This commit is contained in:
parent
7b5aa05b02
commit
72018f7be7
1 changed files with 12 additions and 0 deletions
|
@ -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];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue