Skip to content

Conversation

tybanash
Copy link

No description provided.

/*
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well the solution works.
Can you think of a way to take out this if else statement?

Suggested change
if((str.split("").reverse("").join("")) == str) {
if((str.split("").reverse("").join("")) == str) {

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Thanks for the feedback.

/*
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also you should always try to do both type and value comparisons using ===

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay.

@@ -0,0 +1,15 @@
//defines function reverseString and gives it a parameter str
function reverseString(str) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also your solution will fail for a case such as Racecar

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants