本文整理汇总了TypeScript中lodash.takeRight函数的典型用法代码示例。如果您正苦于以下问题:TypeScript takeRight函数的具体用法?TypeScript takeRight怎么用?TypeScript takeRight使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了takeRight函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: if
const calculatePromotionDiscount = (promo: PromotionModel, validItems: StockItemModel[], otherPromos?: any[]) => {
let discount = 0;
let affectedSKUs = [];
let affectedItems = [];
let applyId = '';
const itemsSortedByPrice = _.sortBy(validItems, 'cost').reverse();
if(promo.itemReductionType === 'All') {
if(promo.discountType === 'Dollar') {
discount = promo.discountValue;
} else {
const thisItem = itemsSortedByPrice[0];
discount = thisItem.cost * (promo.discountValue / 100);
affectedItems.push(thisItem);
}
affectedSKUs = [itemsSortedByPrice[0].sku];
} else if(promo.itemReductionType === 'BuyXGetNext') {
const priceComparator = itemsSortedByPrice[0];
const otherItems = _.takeRight(itemsSortedByPrice, promo.numItemsRequired);
affectedItems = [priceComparator, ...otherItems];
if(promo.discountType === 'Dollar') {
discount = promo.discountValue;
} else {
discount = Math.min(priceComparator.cost, _.last(otherItems).cost * (promo.discountValue / 100));
}
affectedSKUs = _.map(affectedItems, 'sku');
} else if(promo.itemReductionType === 'SetTo') {
const itemsAppliedTo = _.filter(validItems, item => {
return _.find(otherPromos, checkPromo => checkPromo.applyId === item.promoApplyId);
});
const nextPrice = itemsAppliedTo.length;
const basePrices = distribute(2)(promo.numItemsRequired)(promo.discountValue).reverse();
const allPrices = _.flatten(fill(basePrices)(promo.numItemsRequired));
const chosenItem = validItems[nextPrice];
affectedItems = [chosenItem];
discount = chosenItem.cost - allPrices[nextPrice];
affectedSKUs = [chosenItem.sku];
}
applyId = _.last(affectedItems).promoApplyId;
return { discount, affectedSKUs, affectedItems, applyId };
};
示例2: pick
export function computeUndoStacks<T extends Record<string, any>>(
state: UndoHistoryState = initialState,
action: FSA,
previousAppState: T,
presentAppState: T,
config: UndoHistoryConfig,
): UndoHistoryState {
const { past, present, future } = state;
// If action is undo/redoable, store state
if (config.actionsToWatch.includes(action.type)) {
// Append actual present to past, and drop history past config.limit
// Limit only enforced here since undo/redo only shift the history around without adding new history
const appendedPast = [...past, pick(previousAppState, config.whitelist)];
const newPast = 'limit' in config ? takeRight(appendedPast, config.limit) : appendedPast;
return {
past: newPast,
present: pick(presentAppState, config.whitelist),
future: [],
};
}
switch (action.type) {
case UNDO: {
// Abort if no past, or present is unknown
if (past.length === 0 || !present) return state;
const previous = last(past);
const newPast = past.slice(0, past.length - 1);
return {
past: newPast,
present: previous,
future: [present, ...future],
};
}
case REDO: {
// Abort if no future, or present is unknown
if (future.length === 0 || !present) return state;
const next = future[0];
const newFuture = future.slice(1);
return {
past: [...past, present],
present: next,
future: newFuture,
};
}
default: {
return state;
}
}
}
示例3: _handleMotion
private async _handleMotion(): Promise<boolean> {
let keyHandled = false;
let keysPressed: string;
for (let window = this._keyHistory.length; window > 0; window--) {
keysPressed = _.takeRight(this._keyHistory, window).join('');
if (this.keyToNewPosition[keysPressed] !== undefined) {
keyHandled = true;
break;
}
}
if (keyHandled) {
this._selectionStop = await this.keyToNewPosition[keysPressed](this._selectionStop);
this.motion.moveTo(this._selectionStart.line, this._selectionStart.character);
/**
* Always select the letter that we started visual mode on, no matter
* if we are in front or behind it. Imagine that we started visual mode
* with some text like this:
*
* abc|def
*
* (The | represents the cursor.) If we now press w, we'll select def,
* but if we hit b we expect to select abcd, so we need to getRight() on the
* start of the selection when it precedes where we started visual mode.
*/
// TODO this could be abstracted out
if (this._selectionStart.compareTo(this._selectionStop) <= 0) {
this.motion.select(this._selectionStart, this._selectionStop);
} else {
this.motion.select(this._selectionStart.getRight(), this._selectionStop);
}
this._keyHistory = [];
}
return keyHandled;
}
示例4: _handleOperator
private async _handleOperator(): Promise<boolean> {
let keysPressed: string;
let operator: Operator;
for (let window = this._keyHistory.length; window > 0; window--) {
keysPressed = _.takeRight(this._keyHistory, window).join('');
if (this._keysToOperators[keysPressed] !== undefined) {
operator = this._keysToOperators[keysPressed];
break;
}
}
if (operator) {
if (this._selectionStart.compareTo(this._selectionStop) <= 0) {
await operator.run(this._selectionStart, this._selectionStop.getRight());
} else {
await operator.run(this._selectionStart.getRight(), this._selectionStop);
}
}
return !!operator;
}
示例5:
this.db.getAllVideosForGroupFromDB("Recently Played", data => {
// take top 30
let top30RecentlyPlayed = _.takeRight(
_.uniqBy(data, "ytid"),
AppConfig.maxRecentlyPlayedVideos
);
// console.log(`before: ${data.length}`);
// console.log(`after: ${top30RecentlyPlayed.length}`);
if (req.body.trim) {
console.log("Trimming the Recently Played group");
// delete all recently played from db
this.db.deleteRecentlyPlayedVideosFromDB();
// add trimmed recently played back to DB
_.forEach(top30RecentlyPlayed, rp => {
this.db.addVideoToDB(rp.title, rp.ytid, "Recently Played");
});
}
res.json(top30RecentlyPlayed);
});
示例6: handleKeyEvent
async handleKeyEvent(key : string): Promise<Boolean> {
this._keyHistory.push(key);
let keyHandled = false;
let keysPressed: string;
let command: Command;
for (let window = this._keyHistory.length; window > 0; window--) {
keysPressed = _.takeRight(this._keyHistory, window).join('');
command = this._keymap[keysPressed];
if (command !== undefined) {
keyHandled = true;
break;
}
}
if (keyHandled) {
this._keyHistory = [];
await this.handleKey(command)(this.motion);
}
return true;
}
示例7:
calculated: ({ values }) => {
return {
top5Positive: _.take(values, 5),
top5Negative: _.takeRight(values, 5)
};
}
示例8:
listMessages: jasmine.createSpy('listMessages', (groupId: string, options?: any) => {
if (options && options.query.limitToLast) {
return Observable.of(_.takeRight(messages, options.query.limitToLast.value));
}
return Observable.of(messages);
}).and.callThrough(),
示例9: it
it('should move a child', async () => {
const page = await confluency.changeParent(pageIds[1], pageIds[2]);
_.takeRight(page.ancestors, 1)[0].title.should.be.exactly('parent 2');
});
示例10: takeRight
fn: (context, args) => ({
...context,
rows: takeRight(context.rows, args.count),
}),