Palindrome with JavaScript

Brandon S. Ha
Jan 11, 2022

I was trying to approach this problem by splitting half. For example,

12421

set the mid “4” and then split left and right. Define these like left = [1,2], right=[2,1] and mid=4. So all i have to do is right.reverse() to compare with left part. if(left === right.reverse()) should return “YES” else it’s not!

If the each row’s length is even number,

For example, if the length is 6, the left and right length should be 3.

My rubbish code :)

Could make it way short and easy to read.

set each line as a string and then compare the original string and reversed string. If the result is true, return “yes”. Otherwise, should be “no”.

--

--