File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ const checkStringLength = ( string = 'str' , maxLength = 1 ) => string . length <= maxLength ;
2+
3+ checkStringLength ( 'string' , 3 ) ;
4+
5+ const isPalindrome = ( string = '' ) => {
6+ const newString = string . toLowerCase ( ) . replaceAll ( ' ' , '' ) ;
7+ let result = '' ;
8+
9+ for ( let i = newString . length - 1 ; i >= 0 ; i -= 1 ) {
10+ const char = newString [ i ] ;
11+ result += char ;
12+ }
13+
14+ return newString === result ;
15+ } ;
16+
17+ isPalindrome ( 'А роза упала на лапу азора' ) ;
18+
19+ const parseStringToInt = ( string ) => {
20+ string = string . toString ( ) ;
21+ let res = '' ;
22+ for ( let i = 0 ; i < string . length ; i += 1 ) {
23+ const parsed = parseInt ( string [ i ] , 10 ) ;
24+ const isDigit = ( ! isNaN ( parsed ) ) ;
25+ if ( isDigit ) {
26+ res += parsed ;
27+ }
28+ }
29+
30+ return res ? + res : NaN ;
31+ } ;
32+
33+ parseStringToInt ( '78 dogs' ) ;
You can’t perform that action at this time.
0 commit comments