Travis build: 1996

This commit is contained in:
30secondsofcode
2018-04-26 17:45:21 +00:00
parent 3c112ec91f
commit d1a73180b3
2 changed files with 4 additions and 16 deletions

View File

@ -7259,18 +7259,12 @@ pad('foobar', 3); // 'foobar'
Returns `true` if the given string is a palindrome, `false` otherwise.
Convert string `String.toLowerCase()` and use `String.replace()` to remove non-alphanumeric characters from it.
Then, `String.split('')` into individual characters, `Array.reverse()`, `String.join('')` and compare to the original, unreversed string, after converting it `String.tolowerCase()`.
Then, use the spread operator (`...`) to split string into individual characters, `Array.reverse()`, `String.join('')` and compare to the original, unreversed string, after converting it `String.tolowerCase()`.
```js
const palindrome = str => {
const s = str.toLowerCase().replace(/[\W_]/g, '');
return (
s ===
s
.split('')
.reverse()
.join('')
);
return s === [...s].reverse().join('');
};
```