Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. function zbior(){
  3.     var liczby = [];
  4.     for(var i =0;i<arguments.length;i++){
  5.         liczby[i]=arguments[i];
  6.     }
  7.     this.sprawdz = function(x){
  8.         p=false;
  9.         for(var i=0;i<liczby.length;i++){
  10.             if(x==liczby[i]){p=true;}
  11.         }
  12.         return p;
  13.     }
  14.     this.dodaj = function(x){
  15.         x=parseInt(x);
  16.         if(this.sprawdz(x)==false){liczby.push(x);}
  17.        
  18.     }
  19.     this.wypisz = function (){
  20.         for(var i =0;i<liczby.length;i++){
  21.             console.log(liczby[i]);
  22.         }
  23.     }
  24.  
  25.     this.usun = function(x){
  26.         x=parseInt(x);
  27.         for(var i=0;i<liczby.length;i++){
  28.             if(x==liczby[i]){
  29.                 liczby.splice(i,1);
  30.             }
  31.         }
  32.  
  33.     }
  34. }
  35.  
  36. var zbior1 =  new zbior(1,2,6);
  37. zbior1.dodaj(23.13443234);
  38. zbior1.dodaj(23);
  39. zbior1.dodaj(23.1321231231241521);
  40. zbior1.dodaj(24.5);
  41. zbior1.dodaj(26.12);
  42. zbior1.dodaj(2);
  43. zbior1.wypisz();
  44. console.log(zbior1.sprawdz(23));
  45. zbior1.usun(23);
  46. zbior1.wypisz();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement