Here is java script practical example for find second largest biggest Number from the array:
let m1 = [90, 45, 34, 67, 999, 76, 34, 89, 99, 23];
let No1 = 0;
let No2 = 0;
let mcounter = m1.length - 2;
for (let m = 0; m < m1.length; m++) {
let sR = m1[m];
if (mcounter == m) {
break;
}
if (sR > No1) {
No2 = No1; // Store the current No1 as No2
No1 = sR; // Update No1 with the new bigger value
} else if (sR > No2 && sR < No1) {
No2 = sR; // Update No2 with the new second biggest value
}
}
console.log("Second biggest number: " + No2);
No comments:
Post a Comment
Comments