The following function is designed to take numbers out of a string and then add those numbers.
For example, you can enter a string like "What does the iphone6 cost in 2015?" and it should return 2021.
I was able to do 90% of the function, but don't know what the parseInt() function does in the code. I know it is necessary to make it work. Any explanation would be appreciated.
function sumFromString(str){
var sum=0;
var numbers=str.match(/\d+/g);
if(numbers==null){
return 0
}
for(var i=0;i<numbers.length;i++){
sum+=parseInt(numbers[i]);
}
return sum;
}