Created
March 30, 2020 11:59
-
-
Save lordvidex/7e132e421f6e74aad2492f51091da0f8 to your computer and use it in GitHub Desktop.
Owamoyo Evans:: Day 4:: Track 1
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
void countTheWord(String s){ | |
Map<String,int>answer = {}; | |
//first replace all space related symbols or unicodes to ' ' | |
//for uniformity | |
var myString = s.toLowerCase().replaceAll(new RegExp(r'\\t|\\n'),' '); | |
//Regular expression that matches all required words and adds them to map | |
var sh = RegExp(r"(\w+'\w+)|(\w+)"). | |
allMatches(myString).map((m)=>m[0]).forEach((f){ | |
answer[f]==null? | |
answer[f]=1: | |
answer[f]+=1; | |
}); | |
//Output | |
answer.forEach((k,v)=>print('$k: $v')); | |
} | |
void main() { | |
var s = "\"That's the password: 'PASSWORD 123'!\", cried the Special Agent.\nSo I fled."; | |
countTheWord(s); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment