#2108. Find First Palindromic String in the Array
var firstPalindrome = function (words) {
function isPalindrome(word) {
let start = 0, end = word.length - 1
while(start <= end) {
if (word[start] !== word[end]) return false
start++
end--
}
return true
}
for (const word of words) {
if (isPalindrome(word)) return word
}
return ""
};
// var firstPalindrome = function (words) {
// let palindrome
// for (const word of words) {
// palindrome = word.split('').reverse().join('')
// if (palindrome === word) return word
// }
// return ""
// };
ย