-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmax.luau
More file actions
27 lines (20 loc) · 769 Bytes
/
max.luau
File metadata and controls
27 lines (20 loc) · 769 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
--!strict
local maxImpl = require("../utils/max")
--[=[
Returns the maximum value and key in this dictionary.
If any values are comparatively equivalent, the first one found will be returned. (Order is undefined.)
The `comparator` is used in the same way as `table.sort`. If it is not provided, the default comparator is `>`.
```lua
Dictionary.max({ a = 10, b = 200, c = 30 })
-- ( 200, "c" )
Dictionary.max({ alice = child, bertram = teen, charlie = adult }, function(personA, personB)
return personA.age > personB.age
end)
-- ( adult, "charlie" )
```
@within Dictionary
]=]
local function max<Key, Value>(dictionary: { [Key]: Value }, comparator: ((Value, Value) -> boolean)?): (Value, Key?)
return maxImpl(dictionary, comparator)
end
return max