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

148
Views
Compairing two Arrays if they are equal is returning false even if they are the same

With the following code I'm checking if str is a palindrome. (A palindrome is a word or sentence that's spelled the same way both forward and backward). Even tho they are the same, the function is still giving me a false return... Why is that? I know I could join the arrays to single strings with .join('') but I still would like to know whats wrong with my code and why it's not working

function palindrome(str) {
    
      let newStr = str.toUpperCase().replace(/[^A-Z\d]/g, '').split('');
      let newStrRev = [...newStr].reverse();     //.reverse() is not destructive anymore
    
      console.log(typeof newStr, newStr);        //OUTPUT: object [ 'R', 'A', 'C', 'E', 'C', 'A', 'R' ]
      console.log(typeof newStrRev, newStrRev);  //OUTPUT: object [ 'R', 'A', 'C', 'E', 'C', 'A', 'R' ]
    
      if (newStr === newStrRev) {
        return true
      } else {
        return false
      }
    }
    
    console.log(palindrome("race car"));        //OUTPUT: false
about 4 years ago · Santiago Trujillo
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!