kitchen-simulator
Version:
It is a kitchen simulator (self-contained micro-frontend).
30 lines (29 loc) • 945 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.summarizeItems = summarizeItems;
function summarizeItems(items) {
var totalCount = 0;
var totalPrice = 0;
var totalRegularPrice = 0;
for (var sku in items) {
var item = items[sku];
var _ref = item || {},
_ref$count = _ref.count,
count = _ref$count === void 0 ? 0 : _ref$count,
_ref$regularPrice = _ref.regularPrice,
regularPrice = _ref$regularPrice === void 0 ? 0 : _ref$regularPrice,
disCountPrice = _ref.disCountPrice;
var priceToUse = typeof disCountPrice === 'number' && !isNaN(disCountPrice) ? disCountPrice : regularPrice;
totalCount += count;
totalPrice += count * priceToUse;
totalRegularPrice += count * regularPrice;
}
return {
totalCount: totalCount,
totalRegularPrice: totalRegularPrice,
totalPrice: totalPrice,
totalSavings: totalRegularPrice - totalPrice
};
}