Last active
March 27, 2022 13:32
-
-
Save ramthenmala/9528014e90e3cfa7939252f688a31d93 to your computer and use it in GitHub Desktop.
String Palindrome
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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