-
Notifications
You must be signed in to change notification settings - Fork 3
Yasser Moradi edited this page Sep 1, 2015
·
1 revision
Description:
This method returns total of the value in a sequence, The first overload (without any argument) is used for a collation that contains only numeric values.
It also accepts an argument as a selector that selects property of items to be used in some method. That property should be a numeric only.
Samples:
let numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 15, 19];
let stock = [
{ name: 'Apple', category: 'Fruit', price: 0.30 },
{ name: 'Banana', category: 'Fruit', price: 0.35 },
{ name: 'Orange', category: 'Fruit', price: 0.29 },
{ name: 'Cabbage', category: 'Vegetable', price: 0.49 },
{ name: 'Carrot', category: 'Vegetable', price: 0.29 },
{ name: 'Lettuce', category: 'Vegetable', price: 0.30 },
{ name: 'Milk', category: 'Dairy', price: 1.12 }
];
let sum = numbers.asEnumerable().sum();
console.log('sum => ' + sum);
sum = stock.asEnumerable().sum(item => item.price);
console.log('total of stock items price => ' + sum);