UNPKG

itiaaib42nodeumd

Version:

AAIB ITI 42

92 lines (65 loc) 1.66 kB
// var x = 10;//private // global.x = x; // exports.x = x; // console.log(exports);//{} ===> obj.asd = |||| obj["asd"] = // exports.x = x; // console.log(module.exports);// // module.exports.x = x; // module.exports = {x};//{x:10} // exports = {x} // XXXXXX // var y = 20; // function abdElrahman (){ // return "abdElrahman"; // } // module.exports = { // x // ,"rana":y // ,"myFun":abdElrahman // }; //Functions //array allItems //addItem(item, price) ===> {item, price} //getSum() // var Items = []; // function AddItem(item, price){ // Items.push( {item, price} ); // } // function GetSum(){ // // var sum = 0; // // for(let i = 0; i< Items.length; i++){//Items[1].price // // sum += Items[i].price; // // } // // return sum; // return Items.reduce( // (sum,item)=>{return sum+item.price} // ,0 // ) // } // module.exports = { // "Add":AddItem, // "Calc":GetSum // } //Class class ShopingCart{ constructor(){ this.Items = []; } AddItem(item, price){ this.Items.push( {item, price} ); } GetSum(){ return this.Items.reduce( (sum,item)=>{return sum+item.price} ,0 ) } } // var s1 = new ShopingCart() // module.exports = new ShopingCart; // module.exports = new ShopingCart(); // module.exports = ShopingCart(); class Reham{ constructor(){ } } module.exports = {ShopingCart,Reham};