用js编写一个函数,从一个任意字符串中提取所有的数字,然后将它们添加在一起?
注意不能用正则表达式. 使用的知识点只能是js的语法范围.
先谢过了
例如:
Input:“We have 30 apples will be handed out to 10 students who need it, containing 5 foreigners ”.<爱尬聊_生活百科> Output: 30 + 10 + 5 = 45
梦里缠绵的沙发A 18小时前
var str = We have 30 apples will be handed out to 10 students who need it, containing 5 foreigners;
杜宇 18小时前
typeof arr[i] === number
铁小兔 18小时前
把字符串挨着扫描一遍不就完了……