UNPKG

hangul-romanize

Version:
53 lines (52 loc) 2.08 kB
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; var CombinationUtil = /** @class */ (function () { function CombinationUtil() { } /** * 재귀를 통해 조합을 생성하는 내부 static 함수입니다. * * * This private static function recursively builds combinations. * * @param array 2차원 배열 (2D array) * @param current 현재 조합을 저장하는 배열 (Array storing the current combination) * @param depth 현재 2차원 배열의 위치 (Current position in the 2D array) * @param result 가능한 조합을 저장하는 배열 (Array to store possible combinations) */ CombinationUtil.combine = function (array, current, depth, result) { if (depth === array.length) { result.push(__spreadArray([], current, true)); return; } for (var _i = 0, _a = array[depth]; _i < _a.length; _i++) { var item = _a[_i]; current.push(item); this.combine(array, current, depth + 1, result); current.pop(); } }; /** * 주어진 2차원 배열에서 가능한 모든 조합을 생성하여 반환합니다. * 1차 배열의 순서는 바뀌지 않습니다. * * * This static function generates all possible combinations from a given * 2D array, preserving the order of the first dimension. * * @param array 2차원 배열 (2D array) * @returns 가능한 조합의 목록 (List of possible combinations) */ CombinationUtil.getCombinations = function (array) { var result = []; this.combine(array, [], 0, result); return result; }; return CombinationUtil; }()); export { CombinationUtil };