Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

210
Views
How to fix, "TypeError: letters.pop is not a function", issue in my code

I am working on a problem that requires me to reverse a string without having to change the position of characters that are not string, characters like !, (, ), | and so on.

I believe I am almost done solving the problem but I keep getting the error, TypeError: letters.pop is not a function, I tried checking what the position cause might be and i got an hint that .pop cannot be used on any data type that is not an array. I am using the .pop method on an array which is actually valid array but I still keep getting the error.

I think I am missing something out and would be glad if anyone can show it.

let word = "hello-world!"

const isLetter = (word) => {
    return word.toUpperCase() !== word.toLowerCase()
}

const letters = (word) => {
    return [...word].filter((letter) => isLetter(letter))
}

const reverseWord = [...word].map((letter) => isLetter(letter) ? letters.pop() : letter).join("")

console.log(reverseWord)
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

letters.pop() is indeed not a function. pop() is a function on arrays, but letters is not an array. It's a function. Did you mean to invoke it?:

letters(word).pop()

Though keep in mind that the function returns a new array every time it's invoked. So that operation doesn't really do anything useful. Perhaps instead you meant to invoke the function immediately and only once and have letters itself store the resulting array?:

const letters = ((word) => {
    return [...word].filter((letter) => isLetter(letter))
})(word);

Note: I can't speak to whether or not this will make your entire program work as expected. The logic seems strange to me and it's possible there are other problems as well. But the main point here is just that letters itself is not an array in the original code, it's a function that returns an array.

about 4 years ago · Juan Pablo Isaza Report

0

It's because letters was an arrow function not an array. I tried to reproduce your issue and made some changes in it. I have attached one working snippet (it's returning the string in reverse order). Hope that's how you wanted it to work.

let word = "hello-world!"

const isLetter = (word) => {
    return word.toUpperCase() !== word.toLowerCase()
}

const letters = [...word].filter((letter) => isLetter(letter))



const reverseWord = [...word].map((letter) => isLetter(letter) ? letters.pop()  : letter).join("")

console.log(reverseWord)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!