Find the second largest number in a array
function findSecondLargest(arr) {
// Sort the array in descending order
arr.sort(function(a, b) {
return b - a;
});
// Return the element at index 1 (the second largest)
return arr[1];
}
// Example usage
const numbers = [10, 5, 8, 20,...
harikrishna.hashnode.dev1 min read