routie dev init since i didn't adhere to any proper guidance up until now
This commit is contained in:
Generated
Vendored
+24
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Generates all possible combinations of a specific size from an array.
|
||||
*
|
||||
* @param array - The array of strings to generate combinations from.
|
||||
* @param number - The number of elements in each combination.
|
||||
* @returns An array containing all possible combinations.
|
||||
*/
|
||||
function getArrayCombinations(array, number) {
|
||||
let result = []
|
||||
function backtrack(start, comb) {
|
||||
if (comb.length === number) {
|
||||
result.push([...comb])
|
||||
return
|
||||
}
|
||||
for (let i = start; i < array.length; i++) {
|
||||
comb.push(array[i])
|
||||
backtrack(i + 1, comb)
|
||||
comb.pop()
|
||||
}
|
||||
}
|
||||
backtrack(0, [])
|
||||
return result
|
||||
}
|
||||
export { getArrayCombinations }
|
||||
Reference in New Issue
Block a user