Hi everyone.
Let's now code together the first method that we discussed.
Now for this we are going to create a function.
Let's call it is palindrome check.
And we're going to pass in a string to this function.
Now what we're going to do is we're going to create a new string from the back of the given string.
Right.
We'll take character by character from the given string and insert it into the new string.
So let's do that.
For this let's create a empty string.
So let um new string.
To compare.
So I'm just calling it new string to compare.
Now this one is empty.
Now we're going to have a for loop for let I is equal to string dot length minus one.
Because we want to go from the end of the input string right.
And I greater than equal to zero I minus minus.
And as we traverse the input string from back to the front, we are going to take one character at a
time and append it to the new string.
So let's do that new string plus equal to.
String I.
Right?
So at the end of this we would have created a new string.
Now all we need to do is we need to check whether this new string is the same as the given string.
Now if it is the string same, then we will return true, right?
So we can return true.
And if it is not so, if if it's not true, then we can just return false.
All right.
So even over here also, I could have just written because it's just one statement.
So let's just make it smaller.
Now it's one and the same, so I'm just making it smaller.
So we are going to return true if they are the same and if it's not the same, then we are going to
return false.
And that's the function that we have written.
All right.
Now let's test it.
For this I'm creating a string.
So let this A be equal to.
Let's say the given string is ABC.
Now let's pass it and console log what we get to our function.
So is palindrome check.
And we are passing a.
All right.
So let's now see what we get when we run this.
So when I run this, I get false because ABC is not a palindrome.
What about if it's ABC ba?
So and now I get true because it's true.
Yes.
This is a palindrome.
Now what if it's a single character string I get true.
Yes.
So that's good.
And what if I have small A and capital A?
I get false because in the clarification we got the clarification that these are treated separately.
So yes we have coded our first solution.
Now let's take a sample input and see what's actually happening over here.