Check if a character is a digit
JavaScript version
const isDigit = (char) => char < 10;
const isDigit = (char) => char.length === 1 && c >= '0' && c <= '9';
const isDigit = (char) => Boolean([true, true, true, true, true, true, true, true, true, true][char]);
TypeScript version
const isDigit = (char: string): boolean => char < 10;
const isDigit = (char: string): boolean => char.length === 1 && c >= '0' && c <= '9';
const isDigit = (char: string): boolean => Boolean([true, true, true, true, true, true, true, true, true, true][char]);
Examples
isDigit('a');
isDigit('abc');
isDigit(10);
isDigit('10');
isDigit('2');
isDigit(2);