Advertisement
kolarov

16.2

Nov 17th, 2014
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function findCardFrequency(str){
  2.  
  3.     var pattern = new RegExp(/\W/g);
  4.  
  5.     var strings = str[0].split(pattern).filter(Boolean);
  6.  
  7.     var resultArr = {};
  8.  
  9.     for(i=0;i<strings.length;i++){
  10.         resultArr[strings[i]]=0;
  11.     }
  12.  
  13.     for(i=0;i<strings.length;i++){
  14.         resultArr[strings[i]]+=1;
  15.     }
  16.  
  17.  
  18. console.log(resultArr)
  19.  
  20. }
  21.  
  22.  
  23. findCardFrequency(['8♥ 2♣ 4♦ 10♦ J♥ A♠ K♦ 10♥ K♠ K♦']);
  24. findCardFrequency(['J♥ 2♣ 2♦ 2♥ 2♦ 2♠ 2♦ J♥ 2♠']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement