Last active
August 29, 2015 13:59
-
-
Save rvbsanjose/10813404 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
// Using the JavaScript language, have the function NumberSearch(str) take the str parameter, search for all the numbers in the | |
// string, add them together, then return that final number. For example: if str is "88Hello 3World!" the output should be 91. | |
// You will have to differentiate between single digit numbers and multiple digit numbers like in the example above. So | |
// "55Hello" and "5Hello 5" should return two different answers. Each string will contain at least one letter or symbol. | |
// Input = "75Number9" Output = 84 | |
// Input = "10 2One Number*1*" Output = 13 | |
function numCoverter( str ) { | |
var sum = 0; | |
while ( str.match( /\d+/ ) ) { | |
var current = parseInt( str.match( /\d+/ )[0] ); | |
sum += current; | |
str.replace( /\d+/, '' ); | |
} | |
return sum; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment