• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript lodash.takeRight函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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 };
};
开发者ID:Linko91,项目名称:posys,代码行数:56,代码来源:promotion.ts


示例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;
    }
  }
}
开发者ID:nusmodifications,项目名称:nusmods,代码行数:51,代码来源:undoHistory.ts


示例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;
    }
开发者ID:pjvds,项目名称:Vim,代码行数:41,代码来源:modeVisual.ts


示例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;
    }
开发者ID:pjvds,项目名称:Vim,代码行数:22,代码来源:modeVisual.ts


示例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);
    });
开发者ID:frankhale,项目名称:toby,代码行数:22,代码来源:api.ts


示例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;
    }
开发者ID:phoenixinobi,项目名称:Vim,代码行数:23,代码来源:modeNormal.ts


示例7:

 calculated: ({ values }) => {
   return {
     top5Positive: _.take(values, 5),
     top5Negative: _.takeRight(values, 5)
   };
 }
开发者ID:kishoreBhojan,项目名称:ibex-dashboard,代码行数:6,代码来源:bot-framework-inst.ts


示例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(),
开发者ID:bradyisom,项目名称:sp90x2,代码行数:6,代码来源:group.component.spec.ts


示例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');
 });
开发者ID:heycalmdown,项目名称:node-confluence,代码行数:4,代码来源:pages.ts


示例10: takeRight

 fn: (context, args) => ({
   ...context,
   rows: takeRight(context.rows, args.count),
 }),
开发者ID:elastic,项目名称:kibana,代码行数:4,代码来源:tail.ts



注:本文中的lodash.takeRight函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript lodash.takeWhile函数代码示例发布时间:2022-05-25
下一篇:
TypeScript lodash.take函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap