Typescript ES5 Function
Codewars task:
You ask a small girl,"How old are you?" She always says, "x years old", where x is a random number between 0 and 9.
Write a program that returns the girl's age (0-9) as an integer.
Example:
Assume the test input string is always a valid string. For example, the test input may be "1 year old" or "5 years old". The first character in the string is always a number.
Solution:
export const get_age = (age: string): number => Number(age[0])
get_age('4 years old') // Output: 4
Explanation:
The function takes the first character of the age
string and converts it to a number using the Number()
function. This means that the function assumes that the first character of the age
string is a number and will return that number as a result.