Skip to content

Instantly share code, notes, and snippets.

@simbo
Created October 29, 2015 08:18
Show Gist options
  • Save simbo/134b493d7705fd5f9879 to your computer and use it in GitHub Desktop.
Save simbo/134b493d7705fd5f9879 to your computer and use it in GitHub Desktop.
'use strict';
var values = ['A', 'B', 'C', 'D'];
function getCombinations(parts) {
var mix = function(rest) {
return rest.length === 0 ? '' : rest.join('');
};
var combine = function(combinations, firstPart, i, _parts) {
var rest = _parts.filter(function(part) {
return firstPart !== part;
});
if (rest.length > 0) rest = rest.reduce(combine, []);
console.log(rest);
_parts.forEach(function(combination) {
combinations.push(firstPart + combination.join(''));
});
return combinations;
};
return parts.reduce(combine, []);
}
console.log(getCombinations(values));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment