All files / angle-util/dist NumberUtil.js

0% Statements 0/22
0% Branches 0/32
0% Functions 0/2
0% Lines 0/21

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36                                                                       
'use strict';
 
Object.defineProperty(exports, "__esModule", {
    value: true
});
exports.default = {
    random: function random() {
        var diceLimit = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 9;
        var diceBase = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
 
        diceBase > diceLimit ? diceBase = diceLimit : diceBase;
        var diceEnd = diceLimit - diceBase + 1;
        var myRoll = Math.floor(Math.random() * diceEnd) + diceBase;
        return myRoll;
    },
    multiRandom: function multiRandom() {
        var diceNum = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 2;
        var diceLimit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 9;
        var diceBase = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
        var isDuplicate = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
 
        var generatedDices = [];
        for (var i = 0; i < diceNum; i++) {
            var dice = this.random(diceLimit, diceBase);
            if (!isDuplicate && generatedDices.indexOf(dice) !== -1) {
                i--;
            } else {
                generatedDices.push(dice);
            }
        }
        if (generatedDices.length !== diceNum) {
            console.warn('Error: wrong random result counts in multiRandom()@NumberUtil');
        }
        return generatedDices;
    }
};