aboutsummaryrefslogtreecommitdiff
path: root/challenge-235/deadmarshal/lua/ch-2.lua
blob: bca5fbfa84f36b78788298e09071afdd485b78e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/env lua

local function duplicate_zeros(t)
  assert(type(t) == 'table','t must be a table!')
  local ret = {}
  for i=1,#t do
    if #ret == #t then break end
    if t[i] == 0 then
      table.insert(ret,0)
      table.insert(ret,0)
    else
      table.insert(ret,t[i])
    end
  end
  return table.concat(ret,',')
end

print(duplicate_zeros({1,0,2,3,0,4,5,0}))
print(duplicate_zeros({1,2,3}))
print(duplicate_zeros({0,3,0,4,5}))