Logo

Programming-Idioms

History of Idiom 119 > diff from v25 to v26

Edit summary for version 26 by Bug38:
[Lua] removed unused line

Version 25

2017-08-21, 12:38:04

Version 26

2017-08-21, 12:38:32

Idiom #119 Deduplicate list

Remove duplicates from list x.
Explain if original order is preserved.

Illustration

Idiom #119 Deduplicate list

Remove duplicates from list x.
Explain if original order is preserved.

Illustration
Extra Keywords
deduplicate dupe dupes redundant redundancy
Extra Keywords
deduplicate dupe dupes redundant redundancy
Code
local test = {1,2,4,2,3,4,2,3,4,"A", "B", "A"}
local hash = {}
local res = {}

for _,v in ipairs(test) do
   if (not hash[v]) then
       res[#res+1] = v
       hash[v] = true
   end
end
Code
local hash = {}
local res = {}
for _,v in ipairs(test) do
   if (not hash[v]) then
       res[#res+1] = v
       hash[v] = true
   end
end
Doc URL
https://stackoverflow.com/questions/20066835/lua-remove-duplicate-elements
Doc URL
https://stackoverflow.com/questions/20066835/lua-remove-duplicate-elements