Comment detail

アレイのuniq (Nested Flatten)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
function uniq(a)
  local seen = {}
  local a2 = {}
  for _,v in ipairs(a) do
    if not seen[v] then
      seen[v] = true
      table.insert(a2, v)
    end
  end
  return a2
end

function show_array(t)
  print("["..table.concat(t, " ").."]")
end

show_array(uniq{3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9})

Index

Feed

Other

Link

Pathtraq

loading...