File tree Expand file tree Collapse file tree 1 file changed +9
-9
lines changed Expand file tree Collapse file tree 1 file changed +9
-9
lines changed Original file line number Diff line number Diff line change 22 * @param {string[] } strs
33 * @return {string }
44 */
5- var encode = function ( strs ) {
6- let res = "" ;
7- for ( const s of strs ) res += String ( s . length ) + "#" + s ;
8- return res ;
5+ function encode ( strs ) {
6+ return strs . map ( str => `${ str . length } #${ str } ` ) . join ( '' ) ;
97}
108
119/**
1210 * @param {string } str
1311 * @return {string[] }
1412 */
15- var decode = function ( str ) {
13+ function decode ( str ) {
1614 const res = [ ] ;
1715 let i = 0 ;
1816
1917 while ( i < str . length ) {
2018 let j = i ;
21- while ( str [ j ] != "#" ) j += 1 ;
19+ while ( str [ j ] !== "#" ) {
20+ ++ j ;
21+ }
2222
23- length = Number ( str . slice ( i , j ) ) ;
24- res . push ( str . slice ( j + 1 , j + 1 + length ) ) ;
25- i = j + 1 + length ;
23+ const len = Number ( str . slice ( i , j ) ) ;
24+ res . push ( str . slice ( ++ j , j + len ) ) ;
25+ i = j + len ;
2626 }
2727
2828 return res ;
You can’t perform that action at this time.
0 commit comments