Problem:
CodeMaster has just returned from shopping. He scanned the check of the items he bought and gave the resulting string to Ratiorg to figure out the total number of purchased items. Since Ratiorg is a bot he is definitely going to automate it, so he needs a program that sums up all the numbers which appear in the given input.
Help Ratiorg by writing a function that returns the sum of numbers that appear in the given inputString.
Example
For inputString = "2 apples, 12 oranges", the output should be
sumUpNumbers(inputString) = 14.
-Summary-
1. Using for loop, add each character to number only if the character is a digit.
2. If the character is not a number and number is not a zero-length, add the number to res.
3. Add the last number that didn't hit any alphabet or special character if there is.
모든 문제에 대한 저작권은 CodeSignal 회사에 있습니다. [Copyright © 2020 BrainFights Inc. All rights reserved]
'CodeSignal > Arcade' 카테고리의 다른 글
CodeSignal [56/60] digitsProduct (0) | 2020.05.28 |
---|---|
CodeSignal [55/60] differentSquares (0) | 2020.05.28 |
CodeSignal [53/60] validTime (0) | 2020.05.28 |
CodeSignal [52/60] longestWord (0) | 2020.05.28 |
CodeSignal [51/60] deleteDigit (0) | 2020.05.28 |
댓글