Horje
find the second largest number in an array javascript Code Example
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
};
javascript largest number in array
const max = arr => Math.max(...arr);
Source: 1loc.dev
second largest number in array javascript
['20','120','111','215','54','78'].sort(function(a, b) { return b - a; })[1];
// '120'
javascript find the second highest Element from array
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
};
find second largest number in array javascript
var secondMax = function (arr){ 
    var max = Math.max.apply(null, arr), // get the max of the array
        maxi = arr.indexOf(max);
    arr[maxi] = -Infinity; // replace max in the array with -infinity
    var secondMax = Math.max.apply(null, arr); // get the new max 
    arr[maxi] = max;
    return secondMax;
};
find the second largest number in an array javascript
function largestOfFour(mainArray) {
  return mainArray.map(function (subArray){
    return subArray.reduce(function (previousLargestNumber, currentLargestNumber) {
      return (currentLargestNumber > previousLargestNumber) ? currentLargestNumber : previousLargestNumber;
    }, 0);
  });
}
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);




Javascript

Related
image and video lightbox react Code Example image and video lightbox react Code Example
upload preview image js Code Example upload preview image js Code Example
Progress bar loader angular Code Example Progress bar loader angular Code Example
How to extract params from received link in react native firebase dynamiclink? Code Example How to extract params from received link in react native firebase dynamiclink? Code Example
nodejs createcipheriv invalid key length Code Example nodejs createcipheriv invalid key length Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7