Given the input string NEIDESL, I need to generate a superset of every combination of letters this string contains. I've tried a good few answers from StackOverflow.
However, upon executing with my input string, none of the results contain the word DIESEL which leads to me believe they are not complete supersets.
I'm using the follow snippet, found from here:
function strcombinations(str) {
var fn = function(active, rest, a) {
if (!active && !rest)
return;
if (!rest) {
a.push(active);
} else {
fn(active + rest[0], rest.slice(1), a);
fn(active, rest.slice(1), a);
}
return a;
}
return fn("", str, []);
}
I may be misunderstanding what a superset is here, any help appreciated :)
Cheers
//Lets Try this code.
const getAllSubsets =
theArray => theArray.reduce(
(subsets, value) => subsets.concat(
subsets.map(set => [value,...set])
),
[[]]
);
console.log(getAllSubsets(['N','E','I','D','E','S','L']));