Skip to content

Instantly share code, notes, and snippets.

@lordvidex
Created March 30, 2020 11:59
Show Gist options
  • Save lordvidex/7e132e421f6e74aad2492f51091da0f8 to your computer and use it in GitHub Desktop.
Save lordvidex/7e132e421f6e74aad2492f51091da0f8 to your computer and use it in GitHub Desktop.
Owamoyo Evans:: Day 4:: Track 1
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