Palindrome check (recursion)

Easy TimeO(n) SpaceO(n)

A palindrome reads the same forwards and backwards, like "racecar". Given a string s, return true when it is one and false when it is not. The comparison is character by character, and a string of length 0 or 1 is a palindrome.

Examples

Example 1

Input
s = "racecar"
Output
true
r and r, a and a, c and c, with e alone in the middle.

Example 2

Input
s = "hello"
Output
false
h at the front and o at the back are different characters.

The Code

function isPalindrome(s) {
  function check(lo, hi) {
    if (lo >= hi) return true;
    if (s[lo] !== s[hi]) return false;
    return check(lo + 1, hi - 1);
  }
  return check(0, s.length - 1);
}
isPalindrome("racecar");
Done
Step through isPalindrome("racecar") call by call