Q:

javascript largest number in array

const max = arr => Math.max(...arr);
6
const array1 = [1, 3, 2];

Math.max(...array1);
// expected output: 3
5
function findHighestNumber(nums) {
	
	let inputs = nums.filter((val, i) => nums.indexOf(val) === i)
	let max = Math.max(...nums);
	let min = Math.min(...nums);
  
   return max + (-min);
}

console.log(difference([1, 7, 18, -1, -2, 9]));
2
//get min/max value of arrays
function getArrayMax(array){
   return Math.max.apply(null, array);
1

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)); 

0

New to Communities?

Join the community