Answers for "get largest no in the array javascript"

4

get highest value from array javascript

//For Values
var arr =[1,10,3]
var min = Math.min.apply(null, arr),
    max = Math.max.apply(null, arr);

//For Objects
var arr = [{a: 1},{a: 10},{a: 3}]
var values = arr.map(val => val.a);
var max = Math.max.apply(null, values);
console.log(max)
Posted by: Guest on January-21-2021
9

find biggest number in javascript array

var peopleData = [ 
    { name: "Paul", height: 180, age: 21 },
    { name: "Johnny", height: 198, age: 43 },
    { name: "Brad", height: 172, age: 49 },
    { name: "Dwayne", height: 166, age: 15 }
];

//Find biggest height number
var maxHeight = 0;

for (var i = 0; i < heights.length; i++) {
    if (peopleData[i].height > maxHeight) {
        maxHeight = peopleData[i].height;
      //if you console.log(maxHeight); you should get 198
    }
}
Posted by: Guest on May-19-2021
1

function that search a biggest value in array javascript

function maisBaratosQue(valor, precos) {
   return precos.filter(p => p <= valor);
}
Posted by: Guest on September-18-2020
0

get largest no in the array javascript

//For Values
var arr =[1,10,3]
var min = Math.min.apply(null, arr),
    max = Math.max.apply(null, arr);

//For Objects
var arr = [{a: 1},{a: 10},{a: 3}]
var values = arr.map(val => val.a);
var max = Math.max.apply(null, values);
console.log(max)
Posted by: Guest on June-02-2021
0

kth largest element in an array javascript

function nthlargest(arra,highest){
			var x = 0,
				y = 0,
				z = 0,
				temp = 0,
				tnum = arra.length, 
				flag = false, 
				result = false; 
   
			while(x < tnum){
				y = x + 1; 
				
				if(y < tnum){
					for(z = y; z < tnum; z++){
						
						if(arra[x] < arra[z]){
							temp = arra[z];
							arra[z] = arra[x];
							arra[x] = temp;
							flag = true; 
						}else{
							continue;
						}	
					}					
				}
				
				if(flag){
					flag = false;
				}else{
					x++; 
					if(x === highest){ 
                      
						result = true;
					}	
				}
				if(result){
					break;
				}
			}

			return (arra[(highest - 1)]);	
		}
		
console.log(nthlargest([ 43, 56, 23, 89, 88, 90, 99, 652], 4));
Posted by: Guest on January-15-2020
0

javascript set value to the largest value in an array

//get min/max value of arrays
function getArrayMax(array){
   return Math.max.apply(null, array);
Posted by: Guest on November-06-2020

Code answers related to "get largest no in the array javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language