Parse nice int from char problem

Lee·2022년 8월 24일
0

Algorithm

목록 보기
79/92
post-thumbnail

❓ Parse nice int from char problem

Q. 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.

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

//#my solution
function getAge(inputString){
// return the girl's correct age as an integer. Happy coding :) 
  return parseInt(inputString)
}

//#other solution
function getAge(inputString){
  return +inputString[0];
}
profile
Lee

0개의 댓글