JSFiddle - React, Tailwind, and code Playground

by cahnory

JavaScript

var getBestGride = function (num, star) {
    num     = num  || gSe.o_stats.num;
    star    = star || gSe.o_stats.star;
    
    return {
        num:  getBestIn(num,  5),
        star: getBestIn(star, 2)
    };
};
var getBestIn = function (list, n) {
    var
        res = [],
        max = 0,
        maxKey,
        add = function (num, obj) {
            obj.num = num;
            res.push(obj);

            if (res.length > n) {
                res.splice(maxKey, 1);
            }

            max = 0;
            res.forEach(function (item, key) {
                if (item.nbSorties > max) {
                    max = item.nbSorties;
                    maxKey = key;
                }
            });
        },
        i, j;

    for (i = 1; list.hasOwnProperty(i); i++) {
        if (res.length < n || max > list[i].nbSorties) {
            add(i, list[i]);
        }
    }

    return res;
};
getBestGride();


    var gSe = {o_stats: {num:...