Combinations LeetCode solution in JavaScript
1var combine = function (n, k) {2function helper(start, end, combo, subset, answer) {3if (combo == 0) {4answer.push([...subset]);5return;6}7if (end - start + 1 < combo) {8return;9}10if (start > end) {11return;12}13subset.push(start);14helper(start + 1, end, combo - 1, subset, answer);1516subset.pop();17helper(start + 1, end, combo, subset, answer);18}1920const answer = [];21helper(1, n, k, [], answer);22return answer;23};