Skip to content

Instantly share code, notes, and snippets.

@ramthenmala
Last active March 27, 2022 13:32
Show Gist options
  • Save ramthenmala/9528014e90e3cfa7939252f688a31d93 to your computer and use it in GitHub Desktop.
Save ramthenmala/9528014e90e3cfa7939252f688a31d93 to your computer and use it in GitHub Desktop.
String Palindrome
// Palindrome Algorithm
// Method A
function mtdPalindromeA(str){
str = str.toLowerCase()
return( str.toLowerCase() === str.split('').reverse().join('') )
}
mtdPalindromeA('Appa')
mtdPalindromeA('am i a palindrome')
// String Palindrome
function mtdPalindrome(str){
str = str.toLowerCase()
const reversed = str.split('').reverse().join('')
if (str === reversed){
return true
} else{
return false
}
}
mtdPalindrome('Abba')
mtdPalindrome('am i a palindrome')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment