Is Digit

Description


Determine if the given character is a digit or not.

Example

  • For symbol = '0', the output should be isDigit(symbol) = true;

  • For symbol = '-', the output should be isDigit(symbol) = false.

Input/Output

  • [execution time limit] 4 seconds (js)

  • [input] char symbol

A character which is either a digit or not.

  • [output] boolean

true if symbol is a digit, false otherwise.

[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
function isDigit(symbol) {
    return /^\d{1}$/.test(symbol);
}