All files NumberUtil.js

0% Statements 0/14
0% Branches 0/14
0% Functions 0/2
0% Lines 0/13

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                                                 
export default {
    random(diceLimit = 9, diceBase = 0) {
        diceBase > diceLimit ? diceBase = diceLimit : diceBase;
        let diceEnd = diceLimit - diceBase + 1;
        let myRoll = Math.floor(Math.random() * diceEnd) + diceBase;
        return myRoll;
    },
    multiRandom(diceNum = 2, diceLimit = 9, diceBase = 0, isDuplicate = false) {
        let generatedDices = [];
        for (let i = 0; i < diceNum; i++) {
            let 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;
    }
};