function top(array, compare, n) {
        if (n === 0) {
            return [];
        }
        var result = array.slice(0, n).sort(compare);
        var _loop_1 = function (i, m) {
            var element = array[i];
            if (compare(element, result[n - 1]) < 0) {
                result.pop();
                var j = findFirst(result, function (e) { return compare(element, e) < 0; });
                result.splice(j, 0, element);
            }
        };
        for (var i = n, m = array.length; i < m; i++) {
            _loop_1(i, m);
        }
        return result;
    }
Returns the top N elements from the array.

Faster than sorting the entire array when the array is a lot larger than N.

@param array The unsorted array.
@param compare A sort function for the elements.
@param n The number of elements to return.
@return The first n elemnts from array when sorted with compare.