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
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/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.