Logo

Programming-Idioms

History of Idiom 119 > diff from v26 to v27

Edit summary for version 27 by Bug38:
[Lua] added input

Version 26

2017-08-21, 12:38:32

Version 27

2017-08-21, 12:41:52

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 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 x = {'a', 'b', 'c', 'b'}
local hash = {}
local y = {}
for _,v in ipairs(x) do
   if (not hash[v]) then
       y[#y+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