Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // find all combinations
- function combinations(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, []);
- }
- var test = combinations("abcde");
- console.log(test);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement