Update snippet descriptions
This commit is contained in:
@ -3,10 +3,11 @@ title: palindrome
|
||||
tags: string,intermediate
|
||||
---
|
||||
|
||||
Returns `true` if the given string is a palindrome, `false` otherwise.
|
||||
Checks if the given string is a palindrome.
|
||||
|
||||
- Convert the string to `String.prototype.toLowerCase()` and use `String.prototype.replace()` to remove non-alphanumeric characters from it.
|
||||
- Then, use the spread operator (`...`) to split the string into individual characters, `Array.prototype.reverse()`, `String.prototype.join('')` and compare it to the original, unreversed string, after converting it to `String.prototype.toLowerCase()`.
|
||||
- Normalize the string to `String.prototype.toLowerCase()` and use `String.prototype.replace()` to remove non-alphanumeric characters from it.
|
||||
- Use the spread operator (`...`) to split the normalized string into individual characters.
|
||||
- Use `Array.prototype.reverse()`, `String.prototype.join('')` and compare the result to the normalized string.
|
||||
|
||||
```js
|
||||
const palindrome = str => {
|
||||
@ -17,4 +18,4 @@ const palindrome = str => {
|
||||
|
||||
```js
|
||||
palindrome('taco cat'); // true
|
||||
```
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user