本文整理汇总了TypeScript中lodash.reduce函数的典型用法代码示例。如果您正苦于以下问题:TypeScript reduce函数的具体用法?TypeScript reduce怎么用?TypeScript reduce使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了reduce函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: htmlPrintPpCmdsDiff
export function htmlPrintPpCmdsDiff(l : PpCmds, old : PpCmds) : string {
_(patterns).each(pattern => {
l = pattern(l)
old = pattern(old)
})
if (!ppCmdsSameShape(l, old)) {
return markDifferent(
_.reduce(
l,
(acc : string, p : PpCmdType) => {
return acc + htmlPrintPpCmd(p)
},
''
)
)
}
const z = _.zip(l, old)
return _.reduce(
z,
(acc : string, [p, oldP] : [PpCmdType, PpCmdType]) => {
return acc + htmlPrintPpCmdDiff(p, oldP)
},
''
)
}
开发者ID:Ptival,项目名称:PeaCoq,代码行数:25,代码来源:printers.ts
示例2: addHiddenChildTotals
export function addHiddenChildTotals(values) {
let childValues = values;
// Add the Totals Together
let childEntryTotalAgg =
reduce(filter(childValues, (z: any) => { return z.TYPE === 'Total'; })
, (sum = 0, z: any) => {
return sum + Number(z.AMOUNT);
}, 0);
// Get the Sub Category child entires
values = filter(childValues, (z: any) => { return z.TYPE !== 'Total'; });
if (values.length == 0) {
// No Deducated Entries
values = childValues;
} else {
// Get the SubCategory child entry Values that aren't totals
let subValueTotals = reduce(filter(childValues, (z: any) => { return z.TYPE != 'Total'; })
, (sum = 0, z: any) => {
return sum + Number(z.AMOUNT);
}, 0);
// If The Subcategory Entry Values dont add up to the Subcategory Total Value
// Insert a hidden arc on the circle
if (subValueTotals !== childEntryTotalAgg) {
values.push({
AMOUNT: childEntryTotalAgg - subValueTotals,
CATEGORY: "Flexible Earmark",
FUNDING_CATEGORY: "Emergency Reserve",
TYPE: 'Hidden'
})
}
}
return values;
}
开发者ID:Ao21,项目名称:rollup-test,代码行数:33,代码来源:utils.ts
示例3: parseInt
return _.map(outcomeTradeRowsByPeriod, (trades: Array<MarketPriceHistoryRow>, startTimestamp): Candlestick => {
// TODO remove this partialCandlestick stuff and just return
// a Candlestick after the temporary Candlestick.tokenVolume
// is removed (see note on Candlestick.tokenVolume).
const partialCandlestick: Pick<Candlestick, Exclude<keyof Candlestick, "tokenVolume">> = { // this Pick/Exclude stuff just allows us to set the Candlestick.tokenVolume later, but in a typesafe way that prevents typos.
startTimestamp: parseInt(startTimestamp, 10),
start: _.minBy(trades, "timestamp")!.price.toString(),
end: _.maxBy(trades, "timestamp")!.price.toString(),
min: _.minBy(trades, "price")!.price.toString(),
max: _.maxBy(trades, "price")!.price.toString(),
volume: _.reduce(trades, (totalVolume: BigNumber, tradeRow: MarketPriceHistoryRow) => totalVolume.plus(volumeForTrade({
marketMinPrice: marketsRow.minPrice,
marketMaxPrice: marketsRow.maxPrice,
numCreatorTokens: tradeRow.numCreatorTokens,
numCreatorShares: tradeRow.numCreatorShares,
numFillerTokens: tradeRow.numFillerTokens,
numFillerShares: tradeRow.numFillerShares,
})), ZERO).toString(),
shareVolume: _.reduce(trades, (totalShareVolume: BigNumber, tradeRow: MarketPriceHistoryRow) => totalShareVolume.plus(tradeRow.amount), ZERO).toString(), // the business definition of shareVolume should be the same as used with markets/outcomes.shareVolume (which currently is just summation of trades.amount)
};
return {
tokenVolume: partialCandlestick.shareVolume, // tokenVolume is temporary, see note on Candlestick.tokenVolume
...partialCandlestick,
};
});
开发者ID:AugurProject,项目名称:augur_node,代码行数:25,代码来源:get-market-price-candlesticks.ts
示例4: getReportingFees
export async function getReportingFees(db: Knex, augur: Augur, params: t.TypeOf<typeof ReportingFeesParams>): Promise<FeeDetails> {
const currentUniverse = await getUniverse(db, params.universe);
const participantEthFees: Array<ParticipantEthFee> = await getParticipantEthFees(db, augur, params.reporter, params.universe);
const participationTokenEthFees: Array<ParticipationTokenEthFee> = await getParticipationTokenEthFees(db, augur, params.reporter, params.universe);
const result: FormattedMarketInfo = await getMarketsReportingParticipants(db, params.reporter, currentUniverse, participantEthFees);
const repStakeResults = await getStakedRepResults(db, params.reporter, params.universe, result.nonforkedMarkets);
const unclaimedParticipantEthFees = _.reduce(participantEthFees, (acc, cur) => acc.plus(cur.fork ? 0 : cur.ethFees), ZERO);
const unclaimedForkEthFees = _.reduce(participantEthFees, (acc, cur) => acc.plus(cur.fork ? cur.ethFees : 0), ZERO);
const unclaimedParticipationTokenEthFees = _.reduce(participationTokenEthFees, (acc, cur) => acc.plus(cur.ethFees), ZERO);
const redeemableFeeWindows = _.map(participationTokenEthFees, "feeWindow");
const participationTokenRepStaked = _.reduce(participationTokenEthFees, (acc, cur) => acc.plus(cur.participationTokens), ZERO);
const unclaimedRepStaked = repStakeResults.fees.unclaimedRepStaked.plus(participationTokenRepStaked);
return {
total: {
unclaimedParticipationTokenEthFees: unclaimedParticipationTokenEthFees.toFixed(0, BigNumber.ROUND_DOWN),
participationTokenRepStaked: participationTokenRepStaked.toFixed(0, BigNumber.ROUND_DOWN),
unclaimedEth: unclaimedParticipantEthFees.plus(unclaimedParticipationTokenEthFees).toFixed(0, BigNumber.ROUND_DOWN),
unclaimedRepStaked: unclaimedRepStaked.toFixed(0, BigNumber.ROUND_DOWN),
unclaimedRepEarned: repStakeResults.fees.unclaimedRepEarned.toFixed(0, BigNumber.ROUND_DOWN),
lostRep: repStakeResults.fees.lostRep.toFixed(0, BigNumber.ROUND_DOWN),
unclaimedForkEth: unclaimedForkEthFees.toFixed(0, BigNumber.ROUND_DOWN),
unclaimedForkRepStaked: repStakeResults.fees.unclaimedForkRepStaked.toFixed(0, BigNumber.ROUND_DOWN),
},
feeWindows: redeemableFeeWindows.sort(),
forkedMarket: result.forkedMarket,
nonforkedMarkets: repStakeResults.nonforkedMarkets,
};
}
开发者ID:AugurProject,项目名称:augur_node,代码行数:28,代码来源:get-reporting-fees.ts
示例5:
function countBackgroundGoals<T>(goals : IGoals<T>) : number {
return _.reduce(
goals.bgGoals,
(acc, elt) => acc + elt.before.length + elt.after.length,
0
)
}
开发者ID:Ptival,项目名称:PeaCoq,代码行数:7,代码来源:context-panel.ts
示例6: fetchOncoKbAnnotatedGenes
export async function fetchOncoKbAnnotatedGenes(client: OncoKbAPI = oncokbClient): Promise<{[entrezGeneId:number]:boolean}>
{
return _.reduce(await client.genesGetUsingGET({}), (map:{[entrezGeneId:number]:boolean}, next:OncoKbGene)=>{
map[next.entrezGeneId] = true;
return map;
}, {});
}
开发者ID:agarwalrounak,项目名称:cbioportal-frontend,代码行数:7,代码来源:StoreUtils.ts
示例7:
const itemsFromInvoiceToStockable = (items) => {
return _.reduce(items, (prev, cur: StockItemModel) => {
prev[cur.sku] = prev[cur.sku] || 0;
prev[cur.sku] += cur.quantity;
return prev;
}, {});
};
开发者ID:Linko91,项目名称:posys,代码行数:7,代码来源:invoice.ts
示例8: moment
let saveLog = results => {
let application: ApplicationModel = results[0],
basicinfo: ApplicationBasicinfoModel = results[1];
if (isLog === 'true') {
LogModel.setConnection(connection);
let after = _.reduce(admissionInfo.getDocument(),
(result, value) => (result.push(value), result), []);
return LogModel.save({
id: UUID.raw(),
moduleid,
module,
opttype: '1',
nodeid: user.nodeId,
nodetype: user.nodeType,
studentid: id,
cscid: application.cscId,
passportname: basicinfo.fullname,
after: after.join('/'),
before: null,
columnen: null,
columnch: null,
tableen: 'ASMS_ADMISSION',
tablech: '录取信息表',
createby: user.userId,
created: moment().toDate()
});
}
}
开发者ID:wangxin0709,项目名称:csc-scms-node-koa,代码行数:28,代码来源:application-admission-controller.ts
示例9: groupKeyForLineItems
private groupKeyForLineItems(lineItems: ILineItem[]): string {
const sortedLineItems = sortBy(lineItems, 'product.id');
return reduce(sortedLineItems, (key, lineItem) => {
return key + this.groupKeyForLineItem(lineItem);
}, '');
}
开发者ID:lunches-platform,项目名称:fe,代码行数:7,代码来源:price.ts
示例10: Date
let baseData = _.map(data, item => {
return _.reduce(report.columns, (prev, cur: any) => {
if(!cur.checked && !cur.always) { return prev; }
const value = _.get(item, cur.key, '');
prev[cur.name] = value;
if(_.isNull(value)) {
prev[cur.name] = '';
}
if(_.includes(['Purchase Time', 'Last Sold', 'Start Date', 'End Date'], cur.name)) {
if(!value) {
prev[cur.name] = 'Never';
} else {
prev[cur.name] = dateFunctions.format(new Date(value), 'YYYY-MM-DD hh:mm A');
}
}
if(cur.name === 'Purchase Method') {
prev[cur.name] = settings.invoiceMethodDisplay(value);
}
return prev;
}, {});
});
开发者ID:Linko91,项目名称:posys,代码行数:26,代码来源:reportdatatransformer.ts
注:本文中的lodash.reduce函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论