Answers for "find the second largest number in array javascript"

8

find second largest number in array javascript

var secondMax = function (){ 
    var arr = [20, 120, 111, 215, 54, 78]; // use int arrays
    var max = Math.max.apply(null, arr); // get the max of the array
    arr.splice(arr.indexOf(max), 1); // remove max from the array
    return Math.max.apply(null, arr); // get the 2nd max
};
Posted by: Guest on October-14-2020
0

second largest number in array javascript

['20','120','111','215','54','78'].sort(function(a, b) { return b - a; })[1];
// '120'
Posted by: Guest on March-26-2021
1

find the second largest number in array javascript

const input = ['20', '120', '111', '215', '54', '78'];
const secondSort = input.sort(function (a, b) { return b - a}[1])
console.log("===> :: secondSort", secondSort);
Posted by: Guest on April-20-2022
0

finding second highest number in array

public static int secHigh(int arr[]){
  int firstHigh = 0,secHigh = 0;
  for(int x: arr){
    if(x > firstHigh){
      secHigh = firstHigh;
      firstHigh = x;
    }else if(x > secHigh){
      secHigh = x;
    }
  }
  return secHigh;
}
Posted by: Guest on February-07-2022

Code answers related to "find the second largest number in array javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language