Sha256: 3a6c570a99b83edc40c8d935171af07838a74be27a89f3aae73669cc4f280ac8

Contents?: true

Size: 395 Bytes

Versions: 396

Compression:

Stored size: 395 Bytes

Contents

local function append(destination, to_append)
  for _, v in ipairs(to_append) do
    table.insert(destination, v)
  end
end

local function flatten(input)
  local flattened = {}
  for _, element in ipairs(input) do
    if type(element) == 'table' then
      append(flattened, flatten(element))
    else
      table.insert(flattened, element)
    end
  end
  return flattened
end

return flatten

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/lua/exercises/flatten-array/example.lua
trackler-2.2.1.179 tracks/lua/exercises/flatten-array/example.lua
trackler-2.2.1.178 tracks/lua/exercises/flatten-array/example.lua
trackler-2.2.1.177 tracks/lua/exercises/flatten-array/example.lua
trackler-2.2.1.176 tracks/lua/exercises/flatten-array/example.lua
trackler-2.2.1.175 tracks/lua/exercises/flatten-array/example.lua
trackler-2.2.1.174 tracks/lua/exercises/flatten-array/example.lua
trackler-2.2.1.173 tracks/lua/exercises/flatten-array/example.lua
trackler-2.2.1.172 tracks/lua/exercises/flatten-array/example.lua
trackler-2.2.1.171 tracks/lua/exercises/flatten-array/example.lua
trackler-2.2.1.170 tracks/lua/exercises/flatten-array/example.lua
trackler-2.2.1.169 tracks/lua/exercises/flatten-array/example.lua
trackler-2.2.1.167 tracks/lua/exercises/flatten-array/example.lua
trackler-2.2.1.166 tracks/lua/exercises/flatten-array/example.lua
trackler-2.2.1.165 tracks/lua/exercises/flatten-array/example.lua
trackler-2.2.1.164 tracks/lua/exercises/flatten-array/example.lua
trackler-2.2.1.163 tracks/lua/exercises/flatten-array/example.lua
trackler-2.2.1.162 tracks/lua/exercises/flatten-array/example.lua
trackler-2.2.1.161 tracks/lua/exercises/flatten-array/example.lua
trackler-2.2.1.160 tracks/lua/exercises/flatten-array/example.lua