Skip to content

Instantly share code, notes, and snippets.

@ruddha2001
Last active June 24, 2020 10:16
Show Gist options
  • Save ruddha2001/60b0ec79bae019d19c404d417163b0cc to your computer and use it in GitHub Desktop.
Save ruddha2001/60b0ec79bae019d19c404d417163b0cc to your computer and use it in GitHub Desktop.
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