-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmin.luau
More file actions
26 lines (20 loc) · 764 Bytes
/
min.luau
File metadata and controls
26 lines (20 loc) · 764 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
--!strict
local minImpl = require("../utils/min")
--[=[
Returns the minium 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.min({ a = 10, b = 200, c = 30 })
-- ( 10, "a" )
Dictionary.min({ alice = child, bertram = teen, charlie = adult }, function(personA, personB)
return personA.age > personB.age
end)
-- ( child, "alice" )
```
@within Dictionary
]=]
local function min<Key, Value>(dictionary: { [Key]: Value }, comparator: ((Value, Value) -> boolean)?): (Value, Key?)
return minImpl(dictionary, comparator)
end
return min