Hi everyone.
Let's now code the second method that we discussed.
So over here I have the code that we have written as per the first method.
Now there's just a minor change to this right?
Instead of making new string to compare, we have to make this an array.
Right.
So this has to be an array.
So uh, this is an empty array at this point.
Now instead of appending over here we will use dot push right.
So we'll push the characters from the existing string from the back to the front to the array.
So at this point new string to compare this is an array.
And then before we do this comparison we have to join the elements of the array.
So new string to compare at this point is just an array right.
So I'm not changing the name.
This is actually not a string.
This is an array at this point.
So we need to join this to make it a string.
So we use the dot join function for this.
Now at this point this part over here will be a string.
And then we check whether this is equal to the given string.
So if it's equal we return true.
And if it's not we return false.
Now let's test our solution.
So let's call the function is palindrome.
Check.
And let me pass the string ABC to this.
And let's run this and see what we get at this point.
So I'm running it and I get false because ABC is not a palindrome.
What if it was ABC BA at this case I get true right.
Again if I have a A this is true.
If I have a and capital A, this should give us false.
So yes our solution is working.