Last active
November 8, 2021 17:30
-
-
Save castrors/88c2b36861644b68c4c82d1e8c42cac4 to your computer and use it in GitHub Desktop.
Implementation of palindrome in dart
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
import "dart:core"; | |
void main() async { | |
final mymap = { | |
'arara': true, | |
'racecar': true, | |
')(()': true, | |
'radar': true, | |
'()()': false, | |
}; | |
for(var item in mymap.entries){ | |
print('${item.key} is palindrome? should be ${item.value} but ${isPalindrome(item.key) }'); | |
} | |
} | |
bool isPalindrome(String phrase){ | |
final initialPhrase = phrase.replaceAll(RegExp(r'\W'), '').toLowerCase(); | |
final reversedPhrase = initialPhrase.split('').reversed.join(); | |
return initialPhrase == reversedPhrase; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment