This repository was archived by the owner on Apr 2, 2023. It is now read-only.
File tree 4 files changed +40
-1
lines changed
4 files changed +40
-1
lines changed Original file line number Diff line number Diff line change
1
+ import { index } from "../index"
2
+
3
+ describe ( "index" , ( ) => {
4
+ test ( "gets the index item in an array" , ( ) => {
5
+ expect ( index ( 0 ) ( [ 0 , 1 ] ) ) . toBe ( 0 )
6
+ } )
7
+
8
+ test ( "gets the index item in an empty array" , ( ) => {
9
+ expect ( index ( 0 ) ( [ ] ) ) . toBe ( undefined )
10
+ } )
11
+ } )
Original file line number Diff line number Diff line change
1
+ import { last } from "../index"
2
+
3
+ describe ( "last" , ( ) => {
4
+ test ( "gets the last item in an array" , ( ) => {
5
+ expect ( last ( [ 0 , 1 ] ) ) . toBe ( 1 )
6
+ } )
7
+
8
+ test ( "gets the last item in an empty array" , ( ) => {
9
+ expect ( last ( [ ] ) ) . toBe ( undefined )
10
+ } )
11
+ } )
Original file line number Diff line number Diff line change
1
+ import { nth } from "../index"
2
+
3
+ describe ( "nth" , ( ) => {
4
+ test ( "gets the nth item in an array" , ( ) => {
5
+ expect ( nth ( 1 ) ( [ 0 , 1 ] ) ) . toBe ( 0 )
6
+ } )
7
+
8
+ test ( "gets the nth item in an empty array" , ( ) => {
9
+ expect ( nth ( 1 ) ( [ ] ) ) . toBe ( undefined )
10
+ } )
11
+ } )
Original file line number Diff line number Diff line change 1
1
/* eslint-disable @typescript-eslint/no-explicit-any */
2
- export const first = < T > ( items : T [ ] ) : T => items [ 0 ]
2
+ export const index = ( i : number ) => < T > ( items : T [ ] ) : T => items [ i ]
3
+
4
+ export const nth = ( n : number ) => index ( n - 1 )
5
+
6
+ export const first = index ( 0 )
7
+
8
+ export const last = < T > ( items : T [ ] ) : T => items [ items . length - 1 ]
3
9
4
10
export const constant = < T > ( value : T ) => ( ) => value
5
11
You can’t perform that action at this time.
0 commit comments