-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemoveDigitToMax.js
More file actions
33 lines (30 loc) · 958 Bytes
/
Copy pathRemoveDigitToMax.js
File metadata and controls
33 lines (30 loc) · 958 Bytes
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
"use strict"
/**
* @param {string} number
* @param {character} digit
* @return {string}
*/
/**Result
* Runtime: 89 ms, faster than 42.64% of JavaScript online submissions for Remove Digit From Number to Maximize Result.
* Memory Usage: 44 MB, less than 20.47% of JavaScript online submissions for Remove Digit From Number to Maximize Result.
*/
var removeDigit = function (number, digit) {
let num = Array.from(number);
let result = "";
for (let x = 0; x < num.length; x++) {
if (num[x] == digit) {
num.splice(x, 1);
let temp = num.join("");
if (result < temp)
result = temp;
num.splice(x,0,digit);
}
}
return result;
};
(function () {
console.log("12 " + removeDigit("123", "3"));
console.log("231 " + removeDigit("1231", "1"));
console.log("51 " + removeDigit("551", "5"));
console.log("13325 " + removeDigit("133235", "3"));
})()