All files / exercises/palindrome index.ts

100% Statements 14/14
83.33% Branches 10/12
100% Functions 2/2
100% Lines 10/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1832x 7x   5x 5x   5x 7x   5x 5x     3x     1x  
export function isPalindrome(input: string): boolean {
  if (input.length === 0 || input.length === 1) return true;
 
  let i = 0;
  let j = input.length - 1;
 
  while (i < j) {
    if (input[i] !== input[j]) return false;
 
    i++;
    j--;
  }
 
  return true;
}
 
console.log(isPalindrome("racecar"));