Build README
This commit is contained in:
@ -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/).*
|
||||||
|
|
||||||
|
|||||||
@ -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;
|
||||||
}, []);
|
}, []);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user