File tree Expand file tree Collapse file tree 2 files changed +40
-4
lines changed Expand file tree Collapse file tree 2 files changed +40
-4
lines changed Original file line number Diff line number Diff line change
1
+ import Repeat from '../index' ;
2
+
3
+ // Destructure functions exported from bundle
4
+ const { repeat, twice, thrice } = Repeat ( ) ;
5
+
6
+ // Test functions
7
+ test ( 'repeat works correctly and repeats function n times' , ( ) => {
8
+ expect ( repeat ( ( x : number ) => x + 1 , 5 ) ( 1 ) ) . toBe ( 6 ) ;
9
+ } ) ;
10
+
11
+ test ( 'twice works correctly and repeats function twice' , ( ) => {
12
+ expect ( twice ( ( x : number ) => x + 1 ) ( 1 ) ) . toBe ( 3 ) ;
13
+ } ) ;
14
+
15
+ test ( 'thrice works correctly and repeats function thrice' , ( ) => {
16
+ expect ( thrice ( ( x : number ) => x + 1 ) ( 1 ) ) . toBe ( 4 ) ;
17
+ } ) ;
Original file line number Diff line number Diff line change 4
4
* @author Tang Xin Kye, Marcus
5
5
*/
6
6
7
- // eslint-disable-next-line no-underscore-dangle
8
- function repeat ( f : Function , n : any ) {
7
+ /**
8
+ * Repeats function n times
9
+ *
10
+ * @param f - function to be repeated
11
+ * @param n - number of times to be repeated
12
+ * @return a function repeated n times
13
+ */
14
+ function repeat ( f : Function , n : any ) : Function {
9
15
return n === 0 ? ( x : any ) => x : ( x : any ) => f ( repeat ( f , n - 1 ) ( x ) ) ;
10
16
}
11
17
12
- function twice ( f : any ) {
18
+ /**
19
+ * Repeats function twice
20
+ *
21
+ * @param f - function to be repeated
22
+ * @return a function repeated twice
23
+ */
24
+ function twice ( f : Function ) : Function {
13
25
return repeat ( f , 2 ) ;
14
26
}
15
27
16
- function thrice ( f : any ) {
28
+ /**
29
+ * Repeats function thrice
30
+ *
31
+ * @param f - function to be repeated
32
+ * @return a function repeated thrice
33
+ */
34
+ function thrice ( f : Function ) : Function {
17
35
return repeat ( f , 3 ) ;
18
36
}
19
37
38
+ // exported functions from the bundle
20
39
export default ( ) => ( {
21
40
repeat,
22
41
twice,
You can’t perform that action at this time.
0 commit comments