Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitaee5e7a

Browse files
committed
Minor format changes to JS problem 271
1 parent4d2d83d commitaee5e7a

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

‎javascript/271-Encode-and-Decode-Strings.js‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@
22
*@param {string[]} strs
33
*@return {string}
44
*/
5-
varencode=function(strs){
6-
letres="";
7-
for(constsofstrs)res+=String(s.length)+"#"+s;
8-
returnres;
5+
functionencode(strs){
6+
returnstrs.map(str=>`${str.length}#${str}`).join('');
97
}
108

119
/**
1210
*@param {string} str
1311
*@return {string[]}
1412
*/
15-
vardecode=function(str){
13+
functiondecode(str){
1614
constres=[];
1715
leti=0;
1816

1917
while(i<str.length){
2018
letj=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+
constlen=Number(str.slice(i,j));
24+
res.push(str.slice(++j,j+len));
25+
i=j+len;
2626
}
2727

2828
returnres;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp