rellow / src /services /permutation.js
Rafael Camargo
chore: add entries to dataset (total: 96)
ab11d12
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;