Advertisement
Hiteshw11

write a Dart function that counts the frequency of each character (excluding spaces) and prints out

Nov 18th, 2024
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 0.67 KB | Source Code | 0 0
  1. /*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*/
  2.  
  3.  
  4. void main()
  5. {
  6.  
  7.   String a1 ="The quickK brown foxX";
  8.   print(charFreqCount(a1));
  9. }
  10.  
  11.  Map<String,int> charFreqCount(sentence)
  12.  {
  13.   String a2=sentence.replaceAll(' ','');
  14.   List<String> a3=a2.split('');
  15.   print(a3);
  16.   Set<String> s1=Set.from(a3);
  17.   List<String> a4=s1.toList();
  18.   print(a4);
  19.  
  20.   Map<String,int> abc={};
  21.  
  22.   for(int i=0;i<a4.length;i++)
  23.   {
  24.     abc[a4[i]]=0;
  25.   }
  26.  
  27.   for(int i=0;i<a3.length;i++)
  28.   {
  29.     abc[a3[i]]=abc[a3[i]]!+1;
  30.   }
  31.  
  32. //   print(abc);
  33.    
  34.    return(abc);
  35.  
  36. }
Tags: dart
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement