@gamepark/rules-api
Version:
API to implement the rules of a board game
36 lines • 1.18 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.listToListing = exports.listingToList = void 0;
/**
* A listing is a quantity of items indexed by they identifier
* Use this function to get a list of items where each item is included as much time as their listed quantity
* @param listing The listing
* @returns the list matching the listing
*/
function listingToList(listing) {
var list = [];
for (var key in listing) {
var intKey = parseInt(key);
for (var i = 0; i < listing[key]; i++) {
list.push(intKey);
}
}
return list;
}
exports.listingToList = listingToList;
/**
* A listing is a quantity of items indexed by they identifier
* Use this function to get a listing based on a list with potential duplicates
* @param list The list
* @returns the listing matching the list
*/
function listToListing(list) {
var listing = [];
for (var _i = 0, list_1 = list; _i < list_1.length; _i++) {
var t = list_1[_i];
t in listing ? listing[t]++ : listing[t] = 1;
}
return listing;
}
exports.listToListing = listToListing;
//# sourceMappingURL=listing.util.js.map