Advertisement
asternauta

MajsterMajnd (Ulepszone Sprawdz())

Feb 7th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Sprawdz(podane_cyfry)
  2. {
  3.     var rozw = "1234";
  4.     var i = 0, j, wyn = {pasujace: 0, istniejace: 0}, tab_ozn_poz=[], k;
  5.     while (i < podane_cyfry.length)
  6.     {
  7.         j = 0;
  8.         while (j < rozw.length)
  9.         {
  10.             if (rozw[j] == podane_cyfry[i])
  11.             {
  12.                 if (i == j)
  13.                 {                          
  14.                     tab_ozn_poz[i] = 'p';
  15.                 }
  16.                 else
  17.                 {
  18.                     if (tab_ozn_poz[i] != 'p')
  19.                         tab_ozn_poz[i] = 'i';
  20.                 }                              
  21.             }                      
  22.             ++j;
  23.         }
  24.         ++i;
  25.     }
  26.    
  27.     i = 0;
  28.     while (i < tab_ozn_poz.length)
  29.     {
  30.         if (tab_ozn_poz[i] == 'p') ++wyn.pasujace;
  31.         else if (tab_ozn_poz[i] == 'i') ++wyn.istniejace;
  32.        
  33.         ++i;
  34.     }
  35.     return wyn;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement