File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -426,15 +426,19 @@ array = {
426426 return output
427427 end ,
428428
429- -- Create a new table with the sub-table elements concatenated into it
430- -- @param obj {table}
429+ -- Create a new table with the sub-table elements concatenated into it up to the specific depth
430+ -- @param obj {table, depth }
431431 -- @return {table}
432- flat = function (obj )
432+ flat = function (obj , depth )
433+ if depth == nil then
434+ depth = 1 / 0 -- Infinity
435+ end
436+
433437 return array .reduce (obj , function (acc , item )
434- if array .is_array (item ) then
438+ if array .is_array (item ) and depth > 0 then
435439 return array .concat (
436440 acc ,
437- array .flat (item )
441+ array .flat (item , depth - 1 )
438442 )
439443 else
440444 table.insert (acc , item )
You can’t perform that action at this time.
0 commit comments