Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Given a string, write a Dart function that counts the frequency of each character (excluding spaces) and prints out the frequency of each unique character*/
- void main()
- {
- String a1 ="The quickK brown foxX";
- print(charFreqCount(a1));
- }
- Map<String,int> charFreqCount(sentence)
- {
- String a2=sentence.replaceAll(' ','');
- List<String> a3=a2.split('');
- print(a3);
- Set<String> s1=Set.from(a3);
- List<String> a4=s1.toList();
- print(a4);
- Map<String,int> abc={};
- for(int i=0;i<a4.length;i++)
- {
- abc[a4[i]]=0;
- }
- for(int i=0;i<a3.length;i++)
- {
- abc[a3[i]]=abc[a3[i]]!+1;
- }
- // print(abc);
- return(abc);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement