I have to return the largest phone number,not index, from an array in Javascript. I am trying to remove the non digit characters then find largest number. I am new and not experienced with the syntax. Alot of examples show parts of my problem. I don't know how to connect them into one function and how to return the answer. Please help me out. Heres what I have:
function myFunction(array) {
var largest = array.replace(/D/g, '');
for (var i = 0; i < array.length; i++) {
if (largest < array[i]) {
largest = array[i];
}
}
console.log(largest);
}
myFunction([509 - 111 - 1111, 509 - 222 - 2222, 509 - 333 - 3333]);
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…