Advertisement
Guest User

Untitled

a guest
Oct 21st, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. var lista = document.getElementsByTagName("td");
  2. var contor = [];
  3.  
  4. var ture = 100;
  5. var aparitiaNumerelorDeCeleMaiMulteOri = 12;
  6.  
  7. // Play
  8. init();
  9. split();
  10. minim();
  11. maxim();
  12.  
  13. // Init null array
  14. function init(){
  15. for(var j=1;j<=49;j++){
  16. contor[j] = 0;
  17. }
  18. }
  19.  
  20. // Split string into array
  21. function split(){
  22. for(var i=11; i<11+(ture*4); i+=4){
  23. var rezultat = lista[i].innerHTML.split(", ");
  24. rezultat.forEach(numara);
  25. }
  26.  
  27. function numara(item){
  28. contor[item]++;
  29. }
  30. }
  31.  
  32. // Maximul
  33. function maxim(){
  34. max = contor[1];
  35. k = 0;
  36. for(var y=1; y<contor.length;y++){
  37. if(contor[y]>max){
  38. max = contor[y];
  39. }
  40. }
  41.  
  42. do{
  43. for(var y=1; y<contor.length;y++){
  44. if(contor[y]==max && k<aparitiaNumerelorDeCeleMaiMulteOri){
  45. console.log("MAXIM:Numarul " + y + " apare de " + max + " ori");
  46. k++;
  47. }
  48. }
  49. max--;
  50. }while(k!=aparitiaNumerelorDeCeleMaiMulteOri);
  51. }
  52.  
  53. function minim(){
  54. min = contor[1];
  55. k = 0;
  56. for(var y=1; y<contor.length;y++){
  57. if(contor[y]<min){
  58. min = contor[y];
  59. }
  60. }
  61.  
  62. do{
  63. for(var y=1; y<contor.length;y++){
  64. if(contor[y]==min && k<aparitiaNumerelorDeCeleMaiMulteOri){
  65. console.log("MINIM: Numarul " + y + " apare de " + min + " ori");
  66. k++;
  67. }
  68. }
  69. min++;
  70. }while(k!=aparitiaNumerelorDeCeleMaiMulteOri);
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement