var strings = [ '123-456-7777', '223-456-7777', '123-456-7777' ];
var ints = strings.map(el => el.replace(/-/g, '').split('').reduce((sum, a) => sum + +a, 0));
console.log(ints);
if( ints[0] > ints[1] && ints[0] > ints[2]){
console.log(strings[0]);
console.log(ints[0]);
}else if (ints[1] > ints[0] && ints[1] > ints[2]) {
console.log(strings[1]);
console.log(ints[1]);
}else{
console.log(strings[2]);
console.log(ints[2]);
};
I have a few questions.
- Can I replace this If statement with a switch statement?
- I am trying to make the function that prints out the array which has has the largest sum. What other way is there to make this look better?