Skip to content

Files

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Day 35

Write a JavaScript function to get nth largest element from an unsorted array.

Input

nthlargest([ 43, 56, 23, 89, 88, 90, 99, 652], 4)

Output

89

function nthlargest(arr, highest) {
	// write your code here
	return
}


const arr = [43, 56, 23, 89, 88, 90, 99, 652];
const highest = 4;

console.log(nthlargest(arr, highest));

CHALLENGES (0/2 DONE)

  • nthlargest([ 43, 56, 23, 89, 88, 90, 99, 652], 4) returns 89
  • nthlargest([ 10, 100, 1000, 10000], 2) returns 1000

Resources

  • Learn more about implementing MinHeap and MaxHeap here.