Write a single function that outputs the “largest” phone number in an input array (if multiple numbers are equally large, return the last one). Assume that the phone numbers are strings of 10 digits separated by dashes.
I wrote a function to answer the questions above. It comes out undefined. can someone help me find the error please. I feel that i am close to the answer.
var largestNumber = function(strings) {
var ints = strings.map(function(el) {
return el.replace(/-/g, '').split('').reduce(function(previousValue, currentValue, currentIndex, array) {
return previousValue + currentValue;
});
});
console.log(ints);
var largest = Math.max.apply(Math, ints);
return strings[ints.lastIndexOf(largest)];
};
console.log(largestNumber(['111-111-1111', '111-111-1112', '111-111-1113']));