-
Notifications
You must be signed in to change notification settings - Fork 0
/
2023-03-18.js
50 lines (46 loc) · 994 Bytes
/
2023-03-18.js
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* Kata 1 */
/* -------------------------------------- */
/* my solution */
function booleanToString( b ) {
if ( b ) {
return 'true';
} else if ( !b ) {
return 'false';
}
}
console.log( booleanToString( true ) );
/* optimized */
function booleanToString2( b ) {
return b.toString();
}
console.log( booleanToString2( true ) );
/* Kata 2 */
/* -------------------------------------- */
/* my solution */
function removeChar( str ) {
str = str.slice( 1 );
str = str.slice( 0, -1 );
return str;
}
console.log( removeChar( 'flower' ) );
/* optimized */
function removeChar2( str ) {
return str.slice( 1, -1 );
}
console.log( removeChar2( 'flower' ) );
/* Kata 3 */
/* -------------------------------------- */
/* my solution */
function repeatStr( n, s ) {
let str = '';
for ( let i = 0; i < n; i++ ) {
str += s;
}
return str;
}
console.log( repeatStr( 3, 'Bmo' ) );
/* optimized */
function repeatStr2( n, s ) {
return s.repeat( n );
}
console.log( repeatStr2( 3, 'Bmo' ) );