Technical Interview #3: Is String A Palindrome

Interview Question #3:

Write a function that returns if string a palindrome.?❓
Palindrome happens when a string forms the same word when it is reversed.

Example:
abba => true
abcba => true
123xyz => false

If you need practice, t…


This content originally appeared on DEV Community and was authored by Let's Code

Interview Question #3:

Write a function that returns if string a palindrome.?❓
Palindrome happens when a string forms the same word when it is reversed.

Example:
abba => true
abcba => true
123xyz => false

If you need practice, try to solve this on your own. I have included 2 potential solutions below.

Note: There are many other potential solutions to this problem.

Solution #1: Array reverse and join and methods

function isPalindrome(str) {
  return str
    .split('')
    .reverse()
    .join('') === str;
}

Solution #2: array every

function isPalindrome(str) {
  return str.split('').every((char, i) => {
    return char === str[str.length - i - 1]
  })
}

In case you like a video instead of bunch of code ??

Happy coding and good luck if you are interviewing!


This content originally appeared on DEV Community and was authored by Let's Code


Print Share Comment Cite Upload Translate Updates
APA

Let's Code | Sciencx (2021-08-27T02:33:25+00:00) Technical Interview #3: Is String A Palindrome. Retrieved from https://www.scien.cx/2021/08/27/technical-interview-3-is-string-a-palindrome/

MLA
" » Technical Interview #3: Is String A Palindrome." Let's Code | Sciencx - Friday August 27, 2021, https://www.scien.cx/2021/08/27/technical-interview-3-is-string-a-palindrome/
HARVARD
Let's Code | Sciencx Friday August 27, 2021 » Technical Interview #3: Is String A Palindrome., viewed ,<https://www.scien.cx/2021/08/27/technical-interview-3-is-string-a-palindrome/>
VANCOUVER
Let's Code | Sciencx - » Technical Interview #3: Is String A Palindrome. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/08/27/technical-interview-3-is-string-a-palindrome/
CHICAGO
" » Technical Interview #3: Is String A Palindrome." Let's Code | Sciencx - Accessed . https://www.scien.cx/2021/08/27/technical-interview-3-is-string-a-palindrome/
IEEE
" » Technical Interview #3: Is String A Palindrome." Let's Code | Sciencx [Online]. Available: https://www.scien.cx/2021/08/27/technical-interview-3-is-string-a-palindrome/. [Accessed: ]
rf:citation
» Technical Interview #3: Is String A Palindrome | Let's Code | Sciencx | https://www.scien.cx/2021/08/27/technical-interview-3-is-string-a-palindrome/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.