sumankhanal

map_raku1

May 25th, 2020
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 6 0.44 KB | None | 0 0
  1. my %hash;
  2.  
  3. sub count_each_chars($val) {
  4.     if %hash<$val>:exists {
  5.         %hash<$val> = %hash<$val> + 1
  6.     } else {
  7.         %hash<$val> = 1
  8.     }
  9. }
  10.  
  11. "rakuprogramming".comb.map(&count_each_chars);
  12. say %hash
  13.  
  14. # I was expecting {a => 2, g => 2, i => 1, k => 1, m => 2, n => 1, o => 1, p => 1, r => 3, u => 1}
  15. # But I get {$val => 15}
  16. # I know the other way to solve this problem but I want to try this method
  17.  
  18. # What am I missing?
Add Comment
Please, Sign In to add comment