當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript underscore.max函數代碼示例

本文整理匯總了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;未經允許,請勿轉載。