Travis build: 1702
This commit is contained in:
@ -6,7 +6,13 @@ Use `String.toLowerCase()`, `String.replace()` with an appropriate regular expre
|
||||
|
||||
```js
|
||||
const isAnagram = (str1, str2) => {
|
||||
const normalize = str => str.toLowerCase().replace(/[^a-z0-9]/gi, '').split('').sort().join('');
|
||||
const normalize = str =>
|
||||
str
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9]/gi, '')
|
||||
.split('')
|
||||
.sort()
|
||||
.join('');
|
||||
return normalize(str1) === normalize(str2);
|
||||
};
|
||||
```
|
||||
|
||||
@ -15,10 +15,7 @@ const permutations = arr => {
|
||||
return arr.reduce(
|
||||
(acc, item, i) =>
|
||||
acc.concat(
|
||||
permutations([...arr.slice(0, i), ...arr.slice(i + 1)]).map(val => [
|
||||
item,
|
||||
...val,
|
||||
])
|
||||
permutations([...arr.slice(0, i), ...arr.slice(i + 1)]).map(val => [item, ...val])
|
||||
),
|
||||
[]
|
||||
);
|
||||
@ -26,5 +23,5 @@ const permutations = arr => {
|
||||
```
|
||||
|
||||
```js
|
||||
permutations([1, 33, 5]) // [ [ 1, 33, 5 ], [ 1, 5, 33 ], [ 33, 1, 5 ], [ 33, 5, 1 ], [ 5, 1, 33 ], [ 5, 33, 1 ] ]
|
||||
permutations([1, 33, 5]); // [ [ 1, 33, 5 ], [ 1, 5, 33 ], [ 33, 1, 5 ], [ 33, 5, 1 ], [ 5, 1, 33 ], [ 5, 33, 1 ] ]
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user