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

Commitd3482da

Browse files
committed
Create 1323-maximum-69-number.js
1 parentb0f3f52 commitd3482da

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

‎javascript/1323-maximum-69-number.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
*@param {number} num
3+
*@return {number}
4+
*/
5+
varmaximum69Number=function(num){
6+
letmaxArr=[num];// initialize array maxArr with num as value
7+
8+
letnumArr=num.toString().split('');// initialize numArr as array of num
9+
10+
for(leti=0;i<numArr.length;i++){// loop through the every element of array numArr
11+
12+
if(numArr[i]==6){// if current element of numArr is 6
13+
letarr=[...numArr]// copy numArr into arr
14+
arr.splice(i,1,9);// make current element arr to 9
15+
maxArr.push(arr.join(''));// convert arr to string and push into maxArr and break the loop
16+
break;
17+
}
18+
}
19+
20+
returnMath.max(...maxArr);// return max value from maxArr
21+
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp