Logo

Programming-Idioms

History of Idiom 119 > diff from v27 to v28

Edit summary for version 28 by programming-idioms.org:
Admin deletes impl 2094

Version 27

2017-08-21, 12:41:52

Version 28

2017-08-21, 19:41:42

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 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