Skip to content

Instantly share code, notes, and snippets.

@castrors
Last active November 8, 2021 17:30
Show Gist options
  • Save castrors/88c2b36861644b68c4c82d1e8c42cac4 to your computer and use it in GitHub Desktop.
Save castrors/88c2b36861644b68c4c82d1e8c42cac4 to your computer and use it in GitHub Desktop.
Implementation of palindrome in dart
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