var mapFunction2 = function() { emit(this.cust_id, this.items); };
var reduceFunction2 = function(keyCustId, valuesItems) { item_price_sum = 0; item_count = 0; for item in valuesItems { item_price_sum += valuesItems[item].price * valuesItems[item].qty; item_count += valuesItems[item].qty; } return (float)item_price_sum/item_count; };(Edited: 2020-09-30)
mapFunction1 = () => { itemCount = 0; itemPrice = 0; for (let i: this.items){ let {price} = i; itemCount += 1; itemPrice += price; } let average = itemPrice / itemCount; emit(this.cust_id, average); };
reduceFunction1 = (keyCustId, average) => { return average;};(Edited: 2020-09-30)
var mapFunciton1 = function() { var items = this.items; // array of items for(item in items) { emit(this.cust_id, {qty: item.qty, price: item.price}); } };
var reduceFunction1 = function(keyCustId, item) { var totalItems += item.qty; var totalPrice += item.price return totalPrice/totalItems; };
var mapFunction = function() { let qty = 0; for(let k in this.item){ qty+=this.item[k].qty; } emit(this.cust_id, this.price, qty); };
var reduceFunction = function(cust_id, price, qty) { return price/qty; };
function mapFunction(){ emit(this.cust_id, this.items); }; function reduceFunction(keyCustId, items){ var itemPrice = 0; var quantity = 0; items.forEach(function (item) { itemPrice += item.price* item.quantity; quantity += item.quantity; }); return itemPrice/quantity; };(Edited: 2020-09-30)
var mapFunction1 = function() { this.items.forEach(function(item){ emit(this.cust_id, {price: item.price, qty: item.qty}); }); };
var reduceFunction1 = function(keyCustId, itemQtyAndPrices) { return Array.sum(itemQtyAndPrices.price)/Array.sum(itemQtyAndPrices.qty); };
var mapFunction = function() { emit(this.cust_id, this.item); };
var reduceFunction = function(keyCustId, item) { var totalItems += item.qty; var totalPrice += item.price return totalPrice/totalItems; };
var mapFunction = function() { emit(this.cust_id, this.items); }; var reduceFunction = function(keyCustId, items) { sum = 0; count = 0; for item in items { sum += items[item].price * items[item].qty; count += items[item].qty; } return sum/count; };