function mergeIdenticalArrayItemsIntoObject(data, oldObject) {
                        var seen = oldObject;
                        //$log.debug('mergeIdenticalArrayItemsIntoObject:data', data);
                        angular.forEach(data, function (e, i) {
                            if (seen.hasOwnProperty(e.name) && seen[e.name] === e.name) {
                                seen[e['name']]['price'] = e['price']; //Sum their prices
                                seen[e['name']]['quantity'] += 1; //Increment their quantity
                                seen[e['name']]['amount'] = seen[e['name']]['amount'] * seen[e['name']]['quantity']; //Sum their prices
                                //$log.debug('merged', seen[e['name']]);
                            } else {
                                seen[e['name']] = {};
                                seen[e['name']]['name'] = e['name'];
                                seen[e['name']]['price'] = e['price'];
                                seen[e['name']]['quantity'] = 1;
                                seen[e['name']]['amount'] = e['amount'];
                            }
                        });
                        //$log.debug('mergeIdenticalArrayItems', seen);
                        return seen;
                    }
// properties and keeping track of quantities
properties and keeping track of quantities
properties and keeping track of quantities
function mergeIdenticalArrayItemsIntoObject(data, oldObject) {
                        var seen = oldObject;
                        angular.forEach(data, function (e, i) {
                            if (seen.hasOwnProperty(e.name) && seen[e.name] === e.name) {
                                seen[e['name']]['price'] = e['price']; 
                                seen[e['name']]['quantity'] += 1; 
                                seen[e['name']]['amount'] = seen[e['name']]['amount'] * seen[e['name']]['quantity']; 
                            } else {
                                seen[e['name']] = {};
                                seen[e['name']]['name'] = e['name'];
                                seen[e['name']]['price'] = e['price'];
                                seen[e['name']]['quantity'] = 1;
                                seen[e['name']]['amount'] = e['amount'];
                            }
                        });
                        return seen;
                    }
function mergeIdenticalArrayItemsIntoObject ( data , oldObject ) { var seen = oldObject ; angular . forEach ( data , function ( e , i ) { if ( seen . hasOwnProperty ( e . name ) && seen [ e . name ] === e . name ) { seen [ e [ 'name' ] ] [ 'price' ] = e [ 'price' ] ; seen [ e [ 'name' ] ] [ 'quantity' ] += 1 ; seen [ e [ 'name' ] ] [ 'amount' ] = seen [ e [ 'name' ] ] [ 'amount' ] * seen [ e [ 'name' ] ] [ 'quantity' ] ; } else { seen [ e [ 'name' ] ] = { } ; seen [ e [ 'name' ] ] [ 'name' ] = e [ 'name' ] ; seen [ e [ 'name' ] ] [ 'price' ] = e [ 'price' ] ; seen [ e [ 'name' ] ] [ 'quantity' ] = 1 ; seen [ e [ 'name' ] ] [ 'amount' ] = e [ 'amount' ] ; } } ) ; return seen ; }
properties and keeping track of quantities
properties and keeping track of quantities
//$log.debug('mergeIdenticalArrayItemsIntoObject:data', data); //Sum their prices //Increment their quantity //Sum their prices //$log.debug('merged', seen[e['name']]); //$log.debug('mergeIdenticalArrayItems', seen);