Skip to content

Instantly share code, notes, and snippets.

@RachelSa
RachelSa / removeLargest
Created July 7, 2016 22:57
removes n number of elements from an array, largest to smallest
//remove n number of elements from an array, largest to smallest
function removeLargest(arr,n){
for (var i = 0; i < n; i ++){
var sorted = Math.max.apply(null, arr);
//run through array, funding largest
var rem = arr.splice(arr.indexOf(sorted),1);
//remove largest
} console.log(arr);
}