Показать сообщение отдельно
  #7 (permalink)  
Старый 16.11.2017, 19:59
Кандидат Javascript-наук
Отправить личное сообщение для Lion777 Посмотреть профиль Найти все сообщения от Lion777
 
Регистрация: 04.11.2017
Сообщений: 117

Вот маленький пример, а дальше сами, все можно сделать без циклов
class box{
    constructor(width,length,height,mass,cost,price,description,id,sendDate,sender,accepter){
         this.wi=width;
         this.le=length;
         this.he=height;
         
         this.v = (width * length * height); // объём
         
         this.ma=mass;
         this.co=cost; // ценность
         this.pr=price; // стоимость
         this.de=description;
         this.id=id;
         this.da=sendDate;
         this.se=sender;
         this.ac=accepter;
        
         box.amount   += this.v;
         box.totalSum += price;
    }
    
    
}
    var pack=Array();
     
       box.amount = 0;
       box.totalSum = 0;
       
       pack[0]=new box(0.3,0.5,0.1,1.5,200.15,30,"Hamster","02350002243890","2017-11-02","TPT, 10135, Eesti, Harjumaa, Tallinn, Pärnu mnt 57","TPT, 10135, Eesti, Harjumaa, Tallinn, Pärnu mnt 57");
       pack[1]=new box(0.3,0.5,0.1,3.5,10.56,50,"Gold","02350002243832","2017-10-15","Estonia Bank","Findland Bank");
       pack[2]=new box(0.3,0.5,0.1,0.5,53.14,100,"Silver","02350002243891","2017-06-22","Findland Bank","Estonian bank");
       pack[3]=new box(0.3,0.5,0.1,1,5000.30,120,"t-shirts","02350002243891","2017-11-15","Aliexpress","TPT, 10135, Eesti, Harjumaa, Tallinn, Pärnu mnt 57");
 
 // Тут общий объем
alert("Общий объём "+box.amount);

 
N=pack.length;
totalMass=0;
for(i=0; i<N; i++){
     totalMass+=pack[i].ma;
}
alert("Общая масса груза: "+totalMass+"кг");
 //Тут удельная цена, по вашему коду
alert("Удельная цена: "+ (box.totalSum/totalMass));
 
C=pack.cost;
totalCost=0;
for(i=0; i<N; i++){
     totalCost+=pack[i].co;
}
alert("Общая ценность груза: "+totalCost+"евро");
 
P=pack.price;
totalPrice=0;
for(i=0; i<N; i++){
     totalPrice+=pack[i].pr;   
}
alert("Общая стоимость груза: "+totalPrice+"евро");

Последний раз редактировалось Lion777, 16.11.2017 в 20:06.
Ответить с цитированием