Added convertBase6ToDice().

This commit is contained in:
Douglas Muth 2017-01-31 23:36:24 -05:00
parent 8aad4ea0ec
commit acf5389ff7

37
main.js
View file

@ -85,6 +85,42 @@ Diceware.getBase6 = function(roll, num_dice) {
} // End of getBase6()
/**
* Convert a base-6 number to a dice roll
*
* @param array roll An array of integers in base-6 notation
* @param integer num_dice The number of dice rolled
*
* @return array An array of integers representing dice rolls
*/
Diceware.convertBase6ToDice = function(roll, num_dice) {
var retval = [];
if (roll.length != num_dice) {
throw("Mismatch between size of roll (" + roll.length + ") and number of dice (" + num_dice + ")");
}
for (var k in roll) {
var num = roll[k];
if (num < 0) {
throw("Value " + num + " is negative!");
}
if (num > 5) {
throw("Value " + num + " is too large!");
}
num++;
retval.push(num);
}
return(retval);
} // End of convertBase6ToDice()
/**
* Roll a die.
*
@ -138,6 +174,7 @@ Diceware.roll_dice = function() {
* @return string The word from the dicelist
*/
Diceware.get_word = function(wordlist, index) {
var retval = wordlist[index];
if (retval) {