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.119 tracks/lua/exercises/flatten-array/example.lua
trackler-2.2.1.118 tracks/lua/exercises/flatten-array/example.lua
trackler-2.2.1.117 tracks/lua/exercises/flatten-array/example.lua
trackler-2.2.1.116 tracks/lua/exercises/flatten-array/example.lua
trackler-2.2.1.115 tracks/lua/exercises/flatten-array/example.lua
trackler-2.2.1.114 tracks/lua/exercises/flatten-array/example.lua
trackler-2.2.1.113 tracks/lua/exercises/flatten-array/example.lua
trackler-2.2.1.111 tracks/lua/exercises/flatten-array/example.lua
trackler-2.2.1.110 tracks/lua/exercises/flatten-array/example.lua
trackler-2.2.1.109 tracks/lua/exercises/flatten-array/example.lua
trackler-2.2.1.108 tracks/lua/exercises/flatten-array/example.lua
trackler-2.2.1.107 tracks/lua/exercises/flatten-array/example.lua
trackler-2.2.1.106 tracks/lua/exercises/flatten-array/example.lua
trackler-2.2.1.105 tracks/lua/exercises/flatten-array/example.lua
trackler-2.2.1.104 tracks/lua/exercises/flatten-array/example.lua
trackler-2.2.1.103 tracks/lua/exercises/flatten-array/example.lua
trackler-2.2.1.102 tracks/lua/exercises/flatten-array/example.lua
trackler-2.2.1.101 tracks/lua/exercises/flatten-array/example.lua
trackler-2.2.1.100 tracks/lua/exercises/flatten-array/example.lua
trackler-2.2.1.99 tracks/lua/exercises/flatten-array/example.lua