Update Check_for_palindrome.md
This commit is contained in:
@ -1,8 +1,7 @@
|
|||||||
### Check For Palindrome
|
### Check for palindrome
|
||||||
|
|
||||||
Steps :
|
Convert string `toLowerCase()` and use `replace()` to remove non-alphanumeric characters from it.
|
||||||
1. First Converted to form in which no non-alphanumeric character is present i.e. string which is to be compared
|
Then, `split('')` into individual characters, `reverse()`, `join('')` and compare to the original, unreversed string, after converting it `tolowerCase()`.
|
||||||
2. Then Converted to palindrome form in which characters will be reversed and will be compared to non-alphanumeric string
|
|
||||||
|
|
||||||
```
|
```
|
||||||
palindrome = str => (str.toLowerCase().replace(/[\W_]/g,'').split('').reverse().join('')==str.toLowerCase().replace(/[\W_]/g,''));
|
palindrome = str => (str.toLowerCase().replace(/[\W_]/g,'').split('').reverse().join('')==str.toLowerCase().replace(/[\W_]/g,''));
|
||||||
|
|||||||
Reference in New Issue
Block a user