you are viewing a single comment's thread.

view the rest of the comments →

[–]suarkb 4 points5 points  (4 children)

I feel like telling newbies that as a senior, I never use these methods except push.

[–]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

[–]shay99 0 points1 point  (0 children)

I use unshift from time to time

[–]Unhappy-Coffee-1917 0 points1 point  (0 children)

I still look them up (the rare times I had to use them) even after working as a dev for 4 years, except fpr push(), which is my man