Delete Digit

Description


Given some integer, find the maximal number you can obtain by deleting exactly one digit of the given number.

Example

  • For n = 152, the output should be deleteDigit(n) = 52;

  • For n = 1001, the output should be deleteDigit(n) = 101.

Input/Output

  • [execution time limit] 4 seconds (js)

  • [input] integer n

Guaranteed constraints: 10 \leq n \leq 10^6.

  • [output] integer

[JavaScript (ES6)] Syntax Tips

1
2
3
4
5
6
// Prints help message to the console
// Returns a string
function helloWorld(name) {
    console.log("This prints to the console when you Run Tests");
    return "Hello, " + name;
}

Solution


1
2
3
4
function deleteDigit(n) {
    var s = String(n).split('').map(Number)
    return Math.max(...s.map((el,i)=>{var r = s.slice(); r.splice(i,1); return Number( r.join(''))}))
}