本文整理汇总了TypeScript中underscore.reduce函数的典型用法代码示例。如果您正苦于以下问题:TypeScript reduce函数的具体用法?TypeScript reduce怎么用?TypeScript reduce使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了reduce函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: AddBusVisitItem
AddBusVisitItem(bookingId, alkhidmatCentre, driver, bus, fuelAmount) {
if (bus == undefined || bus.length <= 0) {
helper.ShowModalPopup("danger", "Bus Info", "Please enter valid vehicle no.!");
return;
}
else if (fuelAmount == "" || fuelAmount == undefined || fuelAmount === 0) {
helper.ShowModalPopup("danger", "Bus Info", "Please enter valid amount!");
return;
}
var counter = this.idCounter++;
var busExist = this.backboneCollection.findWhere({ busId: bus.id });
var driverExist = this.backboneCollection.findWhere({ driverId: driver.id });
if (busExist == undefined && driverExist == undefined) {
this.backboneCollection.push(new busVisitDto.Models.BusVisitDto({
busVisitId: counter,
centreId: alkhidmatCentre.id, centreDesc: alkhidmatCentre.description,
busId: bus.id, busDesc: bus.description,
driverId: driver.id, driverDesc: driver.description,
visitTypeId: "2",
//isAvailableForBooking: false,
//isAvailableForFutureBooking: false,
bookingId: bookingId,
fuelAmount: fuelAmount.replace(",","")
}));
this.busVisitCollectionView.collection = this.backboneCollection;
var sum = _.reduce(this.backboneCollection.models, (memo, item) => memo + parseFloat(item.get("fuelAmount").replace(",","")), 0);
this.paymentView.viewModel.amount(helper.FormatMoney(sum));
}
else {
helper.ShowModalPopup("danger", "Bus Info", "Entry already exists!");
}
}
示例2: function
import * as _ from "underscore";
var sum = _.reduce([1, 2, 3], function(memo, num){ return memo + num; }, 0);
console.log(sum);
示例3: RemoveBusVisitItem
RemoveBusVisitItem(busId, centreId, driverId) {
this.backboneCollection.remove(this.backboneCollection.findWhere({ busId: busId, centreId: centreId, driverId: driverId }));
var sum = _.reduce(this.backboneCollection.models, (memo, item) => memo + parseFloat(item.get("fuelAmount").replace(",","")), 0);
this.paymentView.viewModel.amount(helper.FormatMoney(sum));
}
示例4: getBuckets
return getBuckets().then((buckets) => {
const reservations: MoveReservations = {};
if (settings.farming.makeRoomForItems) {
// reserve one space in the active character
reservations[this.store.id] = {};
makeRoomTypes.forEach((type) => {
reservations[this.store.id][buckets.byId[type].type!] = 1;
});
}
return _.reduce(
items,
(promise, item) => {
// Move a single item. We do this as a chain of promises so we can reevaluate the situation after each move.
return promise
.then(() => {
const vault = D1StoresService.getVault()!;
const vaultSpaceLeft = vault.spaceLeftForItem(item);
if (vaultSpaceLeft <= 1) {
// If we're down to one space, try putting it on other characters
const otherStores = D1StoresService.getStores().filter(
(store) => !store.isVault && store.id !== this.store.id
);
const otherStoresWithSpace = otherStores.filter((store) =>
store.spaceLeftForItem(item)
);
if (otherStoresWithSpace.length) {
if ($featureFlags.debugMoves) {
console.log(
'Farming initiated move:',
item.amount,
item.name,
item.type,
'to',
otherStoresWithSpace[0].name,
'from',
D1StoresService.getStore(item.owner)!.name
);
}
return dimItemService.moveTo(
item,
otherStoresWithSpace[0],
false,
item.amount,
items,
reservations
);
}
}
if ($featureFlags.debugMoves) {
console.log(
'Farming initiated move:',
item.amount,
item.name,
item.type,
'to',
vault.name,
'from',
D1StoresService.getStore(item.owner)!.name
);
}
return dimItemService.moveTo(item, vault, false, item.amount, items, reservations);
})
.then(() => {
if (incrementCounter) {
this.itemsMoved++;
}
})
.catch((e) => {
if (e.code === 'no-space') {
outOfSpaceWarning(this.store);
} else {
toaster.pop('error', item.name, e.message);
}
throw e;
});
},
$q.resolve()
);
});
示例5: subtract
function subtract($all) {
enforce($all).isArray().isNotEmpty();
return _.reduce($all, (memo, num) => memo - num);
}
示例6: getFields
getFields() {
return _.reduce(this.templates, (fields: string[], template: Template) => fields.concat(template.getFields()), []);
}
示例7: add
function add($all) {
enforce($all).isArray().isNotEmpty();
return _.reduce($all, (memo, num) => memo + num);
}
示例8: multiply
function multiply($all) {
enforce($all).isArray().isNotEmpty();
return _.reduce($all, (memo, num) => memo * num);
}
示例9: reduce
.sortBy(key => {
const total = reduce(rankingInfo.termsWeight[key].Weights, (memo, value) => memo + value, 0);
return total;
})
示例10: fn
export function sum<T>(list: T[], summer: _.ListIterator<T, number>): number {
const fn = _.iteratee(summer) as _.ListIterator<T, number>;
return _.reduce(list, (memo, val, index) => {
return memo + fn(val, index, list);
}, 0);
}