This repository was archived by the owner on Sep 5, 2024. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 286286function table .min (self )
287287 return math.min (table.unpack (self ))
288288end
289+
290+ --[[
291+ * Flattens the table, removing any other tables inside `self` and inserting the
292+ * values inside those tables.
293+ *
294+ * @since 1.3.1
295+ *
296+ * @param {table} self - The target table
297+ * @param {boolean} [recursive] - Whether inner tables should also
298+ * be flattened; defaults to false
299+ --]]
300+ function table .flatten (self , recursive )
301+ -- I would have liked to use ipairs() here, but since we'll need to skip
302+ -- added indexes, I couldn't =/
303+ for i = 1 , # self do
304+ if type (self [i ]) == ' table' then
305+ if recursive then
306+ table .flatten (self [i ])
307+ end
308+
309+ for j , v in ipairs (self [i ]) do
310+ table.insert (self , i + j , v )
311+ end
312+
313+ tableIndex = i
314+ i = i + # self [i ] - 1
315+ table.remove (self , tableIndex )
316+ end
317+ end
318+ end
You can’t perform that action at this time.
0 commit comments