code

code

code

/**

 * @param {string} s

 * @return {boolean}

 */

var isPalindrome = function(s) {

  s = s.replace(/[^a-zA-Z\d]/g, '').toLowerCase();

  const isEven = s.length%2 ===0;

  const index1 = Math.floor(s.length/2);

  const index2 = isEven? index1 : index1+1;

  const s1 = s.substring(0,index1);

  const s2 = s.substring(index2).split('').reverse().join('');

  return s1===s2;

};

Report Page