Conversation
| /* | ||
| str is converted to array, array is reversed and converted back to string and checked if the result is equal to str. | ||
| */ | ||
| if((str.split("").reverse("").join("")) == str) { |
There was a problem hiding this comment.
Well the solution works.
Can you think of a way to take out this if else statement?
| if((str.split("").reverse("").join("")) == str) { | |
| if((str.split("").reverse("").join("")) == str) { |
| /* | ||
| str is converted to array, array is reversed and converted back to string and checked if the result is equal to str. | ||
| */ | ||
| if((str.split("").reverse("").join("")) == str) { |
There was a problem hiding this comment.
Also you should always try to do both type and value comparisons using ===
| @@ -0,0 +1,15 @@ | |||
| //defines function reverseString and gives it a parameter str | |||
| function reverseString(str) { | |||
There was a problem hiding this comment.
Also your solution will fail for a case such as Racecar
There was a problem hiding this comment.
I think Racecar is not a palindrome because the reverse gives racecaR. @DanCarl857 please I don't understand why a case like that should be considered.
There was a problem hiding this comment.
technically it's a palindrome because if you make it all lowercase you get a palindrome.
So try making the entire string all lowercase or all uppercase before checking.
PS: Don't forget the mock interview session in a 2mins. Link on slack
No description provided.