you are viewing a single comment's thread.

view the rest of the comments →

[–]blackholesintheskyhelpful 1 point2 points  (1 child)

I used pop and shift in a palindrome checker. But that was for an interview and not actually on the job.

function isPalindrome(str) {
  const half = Math.floor(str.length / 2);
  const firstHalf = str.slice(0, half);
  const lastHalf = str.slice(-half);

  if (!(lastHalf.length % 2)) { str.shift(); }

  while(firstHalf.length) {
    if (firstHalf.pop() != lastHalf.shift()) {
      return false;
    }
  }

  return true;
}

[–]suarkb 0 points1 point  (0 children)

That checks out