JSFiddle - React, Tailwind, and code Playground

by Darby Rathbone

JavaScript

console.log('test');

var $_stats = (function $stats() {
    var insertSort = function insertSort() {
        for (var i = 1; i < this.length; i++) {
            var tmp = this[i],
                j = i;
            while (this[j - 1] > tmp) {
                this[j] = this[j - 1];
                --j;
            }
            this[j] = tmp;
        }

        return this;
    };
    var Stats = function Stats() {
        var mode = function mode() {
            var _c = [],
                max =0;
            this.forEach(function (e, i, a) {
                var _a = a.indexOf(e);
                if (_c[a.indexOf(e)]) {
                    _c[_a] += 1;
                }
                else {
                    _c[_a] = 1;
                }
                if (_c[_a] > max) max = _c[_a];
            });
            if (max === 1)
                max = -1;
            var $c = (this.filter(function (e, i) {
                return max === _c[i];

            }));
                $c.value = max;
            return $c;
        };


        this.lowest = this[0];
        this.highest = this[this.length - 1];
        this.range = this.highest - this.lowest;
        this.mean = this.reduce(function (a, b) {
            return a + (b / this.length)
        }.bind(this), 0);
        this.median = this[Math.floor(this.length / 2)] / 2 + this[Math.ceil(this.length / 2)] / 2;
        this.mode = mode.call(this);
        return this;
    }
    var b = [];
    for (var i = 0; i < 1000; i++) {
        b.push(Math.ceil(100*Math.random()));
    }
    b = Stats.call(insertSort.call(b));
    console.log(b);
    b = b.map(function (e) {
        return e - b.lowest;
    });
});
$_stats();