JSFiddle - React, Tailwind, and code Playground

by aramk

JavaScript

function isPalindrome(str) {
	if (str.length <= 1) {
 		return true;
  }
  let i = 0;
  let j = str.length - 1;
  while (i < j) {
  	if (str[i] !== str[j]) {
    	return false;
    }
    i++;
    j--;
  }
  return true;
}

console.log(isPalindrome('otto'));
console.log(isPalindrome('ottor'));