-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(array/number): add helpers (#25)
- Loading branch information
Showing
6 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--- | ||
permalink: /number/ | ||
--- | ||
|
||
# number | ||
|
||
```jsonnet | ||
local number = import "github.com/jsonnet-libs/xtd/number.libsonnet" | ||
``` | ||
|
||
`number` implements helper functions for processing number. | ||
|
||
## Index | ||
|
||
* [`fn inRange(v, from, to)`](#fn-inrange) | ||
* [`fn maxInArray(arr, default=0)`](#fn-maxinarray) | ||
* [`fn minInArray(arr, default=0)`](#fn-mininarray) | ||
|
||
## Fields | ||
|
||
### fn inRange | ||
|
||
```ts | ||
inRange(v, from, to) | ||
``` | ||
|
||
`inRange` returns true if `v` is in the given from/to range.` | ||
|
||
### fn maxInArray | ||
|
||
```ts | ||
maxInArray(arr, default=0) | ||
``` | ||
|
||
`maxInArray` finds the biggest number in an array | ||
|
||
### fn minInArray | ||
|
||
```ts | ||
minInArray(arr, default=0) | ||
``` | ||
|
||
`minInArray` finds the smallest number in an array |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
local d = import 'doc-util/main.libsonnet'; | ||
|
||
{ | ||
'#': d.pkg( | ||
name='number', | ||
url='github.com/jsonnet-libs/xtd/number.libsonnet', | ||
help='`number` implements helper functions for processing number.', | ||
), | ||
|
||
'#inRange':: d.fn( | ||
'`inRange` returns true if `v` is in the given from/to range.`', | ||
[ | ||
d.arg('v', d.T.number), | ||
d.arg('from', d.T.number), | ||
d.arg('to', d.T.number), | ||
] | ||
), | ||
inRange(v, from, to): | ||
v > from && v <= to, | ||
|
||
'#maxInArray':: d.fn( | ||
'`maxInArray` finds the biggest number in an array', | ||
[ | ||
d.arg('arr', d.T.array), | ||
d.arg('default', d.T.number, default=0), | ||
] | ||
), | ||
maxInArray(arr, default=0): | ||
std.foldl( | ||
std.max, | ||
std.set(arr), | ||
default, | ||
), | ||
|
||
'#minInArray':: d.fn( | ||
'`minInArray` finds the smallest number in an array', | ||
[ | ||
d.arg('arr', d.T.array), | ||
d.arg('default', d.T.number, default=0), | ||
] | ||
), | ||
minInArray(arr, default=0): | ||
std.foldl( | ||
std.min, | ||
std.set(arr), | ||
default, | ||
), | ||
} |