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

@ -61,8 +61,8 @@ Base cases are for string `length` equal to `2` or `1`.
```js ```js
const anagrams = str => { const anagrams = str => {
if(str.length <= 2) return str.length === 2 ? [str, str[1] + str[0]] : [str]; if(str.length <= 2) return str.length === 2 ? [str, str[1] + str[0]] : [str];
return str.split('').reduce( (acc, letter, index) => { return str.split('').reduce( (acc, letter, i) => {
anagrams(str.slice(0, index) + str.slice(index + 1)).map( value => acc.push(letter + value) ); anagrams(str.slice(0, i) + str.slice(i + 1)).map( val => acc.push(letter + val) );
return acc; return acc;
}, []); }, []);
} }
@ -496,3 +496,4 @@ const validateNumber = n => !isNaN(parseFloat(n)) && isFinite(n);
## Credits ## Credits
*Icons made by [Smashicons](https://www.flaticon.com/authors/smashicons) from [www.flaticon.com](https://www.flaticon.com/) is licensed by [CC 3.0 BY](http://creativecommons.org/licenses/by/3.0/).* *Icons made by [Smashicons](https://www.flaticon.com/authors/smashicons) from [www.flaticon.com](https://www.flaticon.com/) is licensed by [CC 3.0 BY](http://creativecommons.org/licenses/by/3.0/).*

View File

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