UNPKG
@prelude/array
Version:
latest (3.0.0)
3.0.0
2.3.1
2.3.0
2.2.0
2.1.0
2.0.0
1.0.0
0.3.2
0.3.1
0.3.0
0.2.0
0.1.2
0.1.1
0.1.0
0.0.1
Array module.
@prelude/array
/
src
/
bounded.ts
9 lines
(6 loc)
•
250 B
text/typescript
View Raw
1
2
3
4
5
6
7
8
9
import
at
from
'./at.js'
/** Like `at` but bounds less than zero index to 0 and out of bound to last. */
const
bounded = <T>(
values
: T[],
index
:
number
):
T
=>
at
(values,
Math
.
min
(values.
length
-
1
,
Math
.
max
(
0
, index)))
export
default
bounded