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

TypeScript underscore.max函数代码示例

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

本文整理汇总了TypeScript中underscore.max函数的典型用法代码示例。如果您正苦于以下问题:TypeScript max函数的具体用法?TypeScript max怎么用?TypeScript max使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了max函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: copy

  _.each(overlaps, (overlappingItems) => {
    if (overlappingItems.length <= 1) {
      return;
    }

    const options: _.Dictionary<DimItem>[] = [];
    // For each item, replace all the others overlapping it with the next best thing
    for (const item of overlappingItems) {
      const option = copy(items);
      const otherItems = overlappingItems.filter((i) => i !== item);
      let optionValid = true;

      for (const otherItem of otherItems) {
        // Note: we could look for items that just don't have the *same* equippingLabel but
        // that may fail if there are ever mutual-exclusion items beyond exotics.
        const nonExotics = itemsByType[otherItem.type].filter((i) => !i.equippingLabel);
        if (nonExotics.length) {
          option[otherItem.type] = _.max(nonExotics, bestItemFn);
        } else {
          // this option isn't usable because we couldn't swap this exotic for any non-exotic
          optionValid = false;
        }
      }

      if (optionValid) {
        options.push(option);
      }
    }

    // Pick the option where the optimizer function adds up to the biggest number, again favoring equipped stuff
    if (options.length > 0) {
      const bestOption = _.max(options, (opt) => sum(Object.values(opt), bestItemFn));
      items = bestOption;
    }
  });
开发者ID:delphiactual,项目名称:DIM,代码行数:35,代码来源:loadout-utils.ts


示例2: pdiImageData

    @Input()
    set pdiImageData(pdiImageData: PDIImageData) {

        if (pdiImageData && pdiImageData.histogram_gray.length) {
            
            var path_string = '';

            var histogram_red_max = _.max(pdiImageData.histogram_red);
            var histogram_green_max = _.max(pdiImageData.histogram_green);
            var histogram_blue_max = _.max(pdiImageData.histogram_blue);
            var histogram_gray_max = _.max(pdiImageData.histogram_gray);

            //Gray
            path_string = 'M0 100';
            for (var i = 0; i <= 255; i++) {
                path_string += ' L' + i + ' ' + (100 - (pdiImageData.histogram_gray[i] / histogram_gray_max * 100));
            }
            path_string += ' L255 100 Z';
            this.graphSVGGray.nativeElement.setAttribute('d', path_string);

            //Red
            path_string = 'M0 100';
            for (var i = 0; i <= 255; i++) {
                path_string += ' L' + i + ' ' + (100 - (pdiImageData.histogram_red[i] / histogram_red_max * 100));
            }
            path_string += ' L255 100 Z';
            this.graphSVGRed.nativeElement.setAttribute('d', path_string);

            //Green
            path_string = 'M0 100';
            for (var i = 0; i <= 255; i++) {
                path_string += ' L' + i + ' ' + (100 - (pdiImageData.histogram_green[i] / histogram_green_max * 100));
            }
            path_string += ' L255 100 Z';
            this.graphSVGGreen.nativeElement.setAttribute('d', path_string);

            //Blue
            path_string = 'M0 100';
            for (var i = 0; i <= 255; i++) {
                path_string += ' L' + i + ' ' + (100 - (pdiImageData.histogram_blue[i] / histogram_blue_max * 100));
            }
            path_string += ' L255 100 Z';
            this.graphSVGBlue.nativeElement.setAttribute('d', path_string);
            
        }

       

    }
开发者ID:luismiguelprs,项目名称:feevale.pdi_playground,代码行数:49,代码来源:component.ts


示例3: getBestItem

 function getBestItem(
   armor: D1ItemWithNormalStats[],
   stats: number[],
   type: string,
   nonExotic = false
 ) {
   // for specific armor (Helmet), look at stats (int/dis), return best one.
   return {
     item: _.max(armor, (o) => {
       if (nonExotic && o.isExotic) {
         return 0;
       }
       let bonus = 0;
       let total = 0;
       // tslint:disable-next-line:prefer-for-of
       for (let i = 0; i < stats.length; i++) {
         const stat = stats[i];
         const scaleType = o.tier === 'Rare' ? 'base' : vm.scaleType;
         const normalStats = o.normalStats[stat];
         total += normalStats[scaleType];
         bonus = normalStats.bonus;
       }
       return total + bonus;
     }),
     bonusType: type
   };
 }
开发者ID:bhollis,项目名称:DIM,代码行数:27,代码来源:loadout-builder.component.ts


示例4: getMaxColumn

function getMaxColumn(item: D1Item): number | undefined {
  if (!item.talentGrid) {
    return undefined;
  }

  return _.max(item.talentGrid.nodes, (node) => node.column).column;
}
开发者ID:bhollis,项目名称:DIM,代码行数:7,代码来源:perkRater.ts


示例5:

  vm.$onInit = () => {
    vm.hiddenColumns = 0;
    if (vm.perksOnly) {
      if (_.find(vm.talentGrid.nodes, { hash: infuseHash })) {
        vm.hiddenColumns += 1;
      }
      if (_.find(vm.talentGrid.nodes, { hash: 2133116599 })) {
        vm.hiddenColumns += 1;
      }
    }

    if (vm.talentGrid) {
      const visibleNodes = vm.talentGrid.nodes.filter((n) => !n.hidden);
      vm.numColumns = _.max(visibleNodes, (n) => n.column).column + 1 - vm.hiddenColumns;
      vm.numRows = vm.perksOnly ? 2 : _.max(visibleNodes, (n) => n.row).row + 1;
    }
  };
开发者ID:bhollis,项目名称:DIM,代码行数:17,代码来源:talent-grid.component.ts


示例6: buildTalentGrid

function buildTalentGrid(item, talentDefs, progressDefs): D1TalentGrid | null {
  const talentGridDef = talentDefs.get(item.talentGridHash);
  if (
    !item.progression ||
    !talentGridDef ||
    !item.nodes ||
    !item.nodes.length ||
    !progressDefs.get(item.progression.progressionHash)
  ) {
    return null;
  }

  const totalXP = item.progression.currentProgress;
  const totalLevel = item.progression.level; // Can be way over max

  // progressSteps gives the XP needed to reach each level, with
  // the last element repeating infinitely.
  const progressSteps = progressDefs.get(item.progression.progressionHash).steps;
  // Total XP to get to specified level
  function xpToReachLevel(level) {
    if (level === 0) {
      return 0;
    }
    let totalXPRequired = 0;
    for (let step = 1; step <= level; step++) {
      totalXPRequired += progressSteps[Math.min(step, progressSteps.length) - 1].progressTotal;
    }

    return totalXPRequired;
  }

  const possibleNodes = talentGridDef.nodes;

  // var featuredPerkNames = item.perks.map(function(perk) {
  //   var perkDef = perkDefs.get(perk.perkHash);
  //   return perkDef ? perkDef.displayName : 'Unknown';
  // });

  let gridNodes = (item.nodes as any[]).map(
    (node): D1GridNode | undefined => {
      const talentNodeGroup = possibleNodes[node.nodeHash];
      const talentNodeSelected = talentNodeGroup.steps[node.stepIndex];

      if (!talentNodeSelected) {
        return undefined;
      }

      const nodeName = talentNodeSelected.nodeStepName;

      // Filter out some weird bogus nodes
      if (!nodeName || nodeName.length === 0 || talentNodeGroup.column < 0) {
        return undefined;
      }

      // Only one node in this column can be selected (scopes, etc)
      const exclusiveInColumn = Boolean(
        talentNodeGroup.exlusiveWithNodes && talentNodeGroup.exlusiveWithNodes.length > 0
      );

      // Unlocked is whether or not the material cost has been paid
      // for the node
      const unlocked =
        node.isActivated ||
        talentNodeGroup.autoUnlocks ||
        // If only one can be activated, the cost only needs to be
        // paid once per row.
        (exclusiveInColumn &&
          _.any(talentNodeGroup.exlusiveWithNodes, (nodeIndex: number) => {
            return item.nodes[nodeIndex].isActivated;
          }));

      // Calculate relative XP for just this node
      const startProgressionBarAtProgress = talentNodeSelected.startProgressionBarAtProgress;
      const activatedAtGridLevel = talentNodeSelected.activationRequirement.gridLevel;
      const xpRequired = xpToReachLevel(activatedAtGridLevel) - startProgressionBarAtProgress;
      const xp = Math.max(0, Math.min(totalXP - startProgressionBarAtProgress, xpRequired));

      // Build a perk string for the DTR link. See https://github.com/DestinyItemManager/DIM/issues/934
      let dtrHash: string | null = null;
      if (node.isActivated || talentNodeGroup.isRandom) {
        dtrHash = (node.nodeHash as number).toString(16);
        if (dtrHash.length > 1) {
          dtrHash += '.';
        }

        if (talentNodeGroup.isRandom) {
          dtrHash += node.stepIndex.toString(16);
          if (node.isActivated) {
            dtrHash += 'o';
          }
        }
      }

      // Generate a hash that identifies the weapons permutation and selected perks.
      // This is used by the Weapon Reviewing system.
      const generateNodeDtrRoll = (node, talentNodeSelected): string => {
        let dtrRoll = node.nodeHash.toString(16);

        if (dtrRoll.length > 1) {
          dtrRoll += '.';
//.........这里部分代码省略.........
开发者ID:bhollis,项目名称:DIM,代码行数:101,代码来源:d1-item-factory.service.ts


示例7:

 let items = _.mapObject(itemsByType, (items) => _.max(items, bestItemFn));
开发者ID:delphiactual,项目名称:DIM,代码行数:1,代码来源:loadout-utils.ts


示例8: applyLoadoutItems

  // Move one loadout item at a time. Called recursively to move items!
  function applyLoadoutItems(
    store: DimStore,
    items: DimItem[],
    loadout: Loadout,
    loadoutItemIds: { id: string; hash: number }[],
    scope: {
      failed: number;
      total: number;
      successfulItems: DimItem[];
    }
) {
    if (items.length === 0) {
      // We're done!
      return $q.when();
    }

    let promise: IPromise<any> = $q.when();
    const pseudoItem = items.shift()!;
    const item = getLoadoutItem(pseudoItem, store);

    if (item) {
      if (item.maxStackSize > 1) {
        // handle consumables!
        const amountAlreadyHave = store.amountOfItem(pseudoItem);
        let amountNeeded = pseudoItem.amount - amountAlreadyHave;
        if (amountNeeded > 0) {
          const otherStores = getStoreService(store.destinyVersion).getStores()
            .filter((otherStore) => store.id !== otherStore.id);
          const storesByAmount = _.sortBy(otherStores.map((store) => {
            return {
              store,
              amount: store.amountOfItem(pseudoItem)
            };
          }), 'amount').reverse();

          let totalAmount = amountAlreadyHave;
          while (amountNeeded > 0) {
            const source = _.max(storesByAmount, (s) => s.amount);
            const amountToMove = Math.min(source.amount, amountNeeded);
            const sourceItem = _.find(source.store.items, { hash: pseudoItem.hash });

            if (amountToMove === 0 || !sourceItem) {
              promise = promise.then(() => {
                const error: Error & { level?: string } = new Error($i18next.t('Loadouts.TooManyRequested', { total: totalAmount, itemname: item.name, requested: pseudoItem.amount }));
                error.level = 'warn';
                return $q.reject(error);
              });
              break;
            }

            source.amount -= amountToMove;
            amountNeeded -= amountToMove;
            totalAmount += amountToMove;

            promise = promise.then(() => dimItemService.moveTo(sourceItem, store, false, amountToMove, loadoutItemIds));
          }
        }
      } else {
        // Pass in the list of items that shouldn't be moved away
        promise = dimItemService.moveTo(item, store, pseudoItem.equipped, item.amount, loadoutItemIds);
      }
    }

    promise = promise
      .then(() => {
        if (item) {
          scope.successfulItems.push(item);
        }
      })
      .catch((e) => {
        const level = e.level || 'error';
        if (level === 'error') {
          scope.failed++;
        }
        toaster.pop(e.level || 'error', item ? item.name : 'Unknown', e.message);
      })
      // Keep going
      .finally(() => applyLoadoutItems(store, items, loadout, loadoutItemIds, scope));

    return promise;
  }
开发者ID:delphiactual,项目名称:DIM,代码行数:82,代码来源:loadout.service.ts


示例9: _setMaximumTotalVotes

 _setMaximumTotalVotes(bulkRankings) {
   this._maxTotalVotes = _.max(_.pluck(_.pluck(bulkRankings, 'votes'), 'total'));
 }
开发者ID:delphiactual,项目名称:DIM,代码行数:3,代码来源:d2-reviewDataCache.ts


示例10: getBestPlace

 getBestPlace(items: Array<Item>): string {
     let bestPlace = _.max(items, function (i) { return i.point });
     return bestPlace.name;
 }
开发者ID:chun4foryou,项目名称:develop,代码行数:4,代码来源:list.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript underscore.memoize函数代码示例发布时间:2022-05-25
下一篇:
TypeScript underscore.mapObject函数代码示例发布时间: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