// generateCombinations.js
/*global adventurejs A*/
/**
* Generate string combinations from an array of substrings.
* @method adventurejs#generateCombinations
* @memberOf adventurejs
* @param {Object} world
*/
adventurejs.generateCombinations = function Adventurejs_generateCombinations(
arrays
) {
function combine(prefix, arrays, index, result) {
if (index === arrays.length) {
result.push(prefix.join(", "));
return;
}
for (let item of arrays[index]) {
combine([...prefix, item], arrays, index + 1, result);
}
}
const result = [];
combine([], arrays, 0, result);
return result;
};