我试图分解每个电话号码(字符串),删除“ - ”,然后将数字的每个数字加在一起,返回最大的数字。我能够删除“ - ”但是我无法接受新数组并添加每个数字返回最大的数字....
var phoneNumbers = ['222-111-2234', '998-887-2222', '991-111-1111'];
for (var i=0;i<phoneNumbers.length;i++) {
var numberString = phoneNumbers[i].replace(/-/g,'');
var number = parseInt(numberString,10);
numbers[i] = number;
}
var largestNumber = numbers[0];
for (var i=0;i<numbers.length;i++) {
if (numbers[i] > largestNumber) {
largestNumber = numbers[i];
}
}
return largestNumber;