Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit efee6ab

Browse files
committed
Add table.min and table.max
1 parent 0162273 commit efee6ab

1 file changed

Lines changed: 27 additions & 1 deletion

File tree

src/Table.lua

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,4 +240,30 @@ end
240240
--]]
241241
function table.average(self)
242242
return table.sum(self) / #self
243-
end
243+
end
244+
245+
--[[
246+
* Returns the maximum value of all items in the given table.
247+
*
248+
* @since 1.1.0
249+
*
250+
* @param {table} self - The target table
251+
*
252+
* @returns {number} - The maximum value of all items
253+
--]]
254+
function table.max(self)
255+
return math.max(table.unpack(self))
256+
end
257+
258+
--[[
259+
* Returns the minimum value of all items in the given table.
260+
*
261+
* @since 1.1.0
262+
*
263+
* @param {table} self - The target table
264+
*
265+
* @returns {number} - The minimum value of all items
266+
--]]
267+
function table.min(self)
268+
return math.min(table.unpack(self))
269+
end

0 commit comments

Comments
 (0)