File size: 446 Bytes
ab11d12 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
const _public = {};
_public.permute = words => {
return [
...halfPermute(words),
...halfPermute(words.reverse())
];
};
function halfPermute(words){
return words.reduce(result => {
const data = result[result.length - 1] || words
return [
...result,
reposition(data)
]
}, []);
}
function reposition(words){
const [firstWord, ...rest] = words;
return [...rest, firstWord];
}
module.exports = _public;
|