Last active
June 24, 2020 10:16
-
-
Save ruddha2001/60b0ec79bae019d19c404d417163b0cc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export namespace DigitsInNumber { | |
// Check if value is a number | |
const isNumber = (value: any): boolean => { | |
return !isNaN(value); | |
}; | |
// Count the digits in the number | |
export const countDigits = (value: any): string => { | |
if (isNumber(value) === false) return "Hey, we need a number!"; | |
if (value < 0) return "We'll ignore negative numbers"; | |
else if (value >= 0 && value <= 9) return "Single Digit"; | |
else if (value >= 10 && value <= 99) return "Double Digit"; | |
else return "More the 2 digits"; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment