Ad
  • Custom User Avatar

    instead of using the first .reverse(), you can just change a-b from the sort() to b-a instead. That way it'll be

    return xs.sort(function(a,b) {return b-a}).slice(0,n).reverse();