Build README

This commit is contained in:
Angelos Chalaris
2017-12-12 18:02:15 +02:00
parent 5ea68ecb00
commit 0142b9e3f6
2 changed files with 5 additions and 4 deletions

View File

@ -8,8 +8,8 @@ Base cases are for string `length` equal to `2` or `1`.
```js
const anagrams = str => {
if(str.length <= 2) return str.length === 2 ? [str, str[1] + str[0]] : [str];
return str.split('').reduce( (acc, letter, index) => {
anagrams(str.slice(0, index) + str.slice(index + 1)).map( value => acc.push(letter + value) );
return str.split('').reduce( (acc, letter, i) => {
anagrams(str.slice(0, i) + str.slice(i + 1)).map( val => acc.push(letter + val) );
return acc;
}, []);
}