当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript lodash.maxBy函数代码示例

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


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

示例1: copy

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

    const options: { [x: string]: 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] = _.maxBy(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 = _.maxBy(options, (opt) => _.sumBy(Object.values(opt), bestItemFn))!;
      items = bestOption;
    }
  });
开发者ID:w1cked,项目名称:DIM,代码行数:35,代码来源:loadout-utils.ts

示例2: 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

示例3: addRow

  addRow() {
    let enc = new Encounter();
    let members = this._data.members;
    
    let maxInit = _.maxBy(members, 'init');
    if (maxInit) enc.init = maxInit.init*1 + 1;
    
    let maxId = _.maxBy(members, 'id');
    if (maxId) enc.id = maxId.id*1 + 1;
    
    this._data.members.push(enc);
    this.sort();

    return enc;
  }
开发者ID:Vargash,项目名称:DMVTools,代码行数:15,代码来源:encounter-data.ts

示例4: getAdjustInformation

export function getAdjustInformation(polyhedron: Polyhedron) {
  const oppositePrismFaces = getOppositePrismFaces(polyhedron);
  if (oppositePrismFaces) {
    return {
      vertexSets: oppositePrismFaces,
      boundary: oppositePrismFaces[0],
      multiplier: 1 / 2,
    };
  }
  const oppositeCaps = getOppositeCaps(polyhedron);
  if (oppositeCaps) {
    // This is an elongated bi-cap
    return {
      vertexSets: oppositeCaps,
      boundary: oppositeCaps[0].boundary(),
      multiplier: 1 / 2,
    };
  }

  // Otherwise it's an elongated single cap
  const faces = polyhedron.faces.filter(face => {
    return _.uniqBy(face.adjacentFaces(), 'numSides').length === 1;
  });
  const face = _.maxBy(faces, 'numSides')!;
  return {
    vertexSets: [face],
    boundary: face,
    multiplier: 1,
  };
}
开发者ID:tessenate,项目名称:polyhedra-viewer,代码行数:30,代码来源:prismUtils.ts

示例5: beforeEach

  beforeEach(() => {
    const context = new ModelContext()
    context.use(new DatabaseExtension())

    model = context
      .object()
      .children({
        id: context.integerId(),
        x: context
          .integer()
          .constrain({type: 'unique'})
          .required(),
        y: context
          .integer()
          .constrain({type: 'immutable'})
          .automanage({event: 'create', supplyWith: v => v.setValue(1)}),
        z: context.integer().automanage({event: '*', supplyWith: v => v.setValue(2)}),
      })
      .constrain({
        type: 'custom',
        meta: {
          evaluate(data) {
            if (data.record.x > 100) {
              throw new Error('x is too big')
            }
          },
        },
      })

    executorMinimal = {
      transaction(f) {
        transaction = {}
        return f(transaction)
      },
      count(query) {
        return executorMinimal.find(query).length
      },
      find(query) {
        return _.filter(executorData, query.where)
      },
      findById(id) {
        return _.filter(executorData, {id})[0]
      },
      save(object) {
        if (!object.id) {
          object.id = executorData.length ? _.maxBy(executorData, 'id').id + 1 : 1
        }

        executorMinimal.destroyById(object.id)
        executorData.push(object)
        return object
      },
      destroyById(id) {
        executorData = executorData.filter(item => item.id !== id)
      },
    }

    executor = new Executor(model, executorMinimal)
    executorData = []
  })
开发者ID:patrickhulce,项目名称:klay,代码行数:60,代码来源:executor.test.ts

示例6: 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: _.maxBy(armor, (o) => {
       if (nonExotic && o.isExotic) {
         return 0;
       }
       let bonus = 0;
       let total = 0;
       for (const stat of stats) {
         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:w1cked,项目名称:DIM,代码行数:25,代码来源:loadout-builder.component.ts

示例7: just

 .subscribe(a => {
   const removedStateIds = a.answer.stateIds
   stmCanceledFiltered$.onNext(a)
   doc.removeSentencesByStateIds(removedStateIds)
   const tip = _.maxBy(doc.getAllSentences(), s => s.sentenceId)
   doc.setTip(tip ? just(tip) : nothing<ISentence<IStage>>())
 })
开发者ID:Ptival,项目名称:PeaCoq,代码行数:7,代码来源:observe-stmcancel.ts

示例8: getOppositePrismFaces

function getOppositePrismFaces(polyhedron: Polyhedron) {
  const face1 = _.maxBy(
    _.filter(polyhedron.faces, face => {
      const faceCounts = _.countBy(
        face.vertexAdjacentFaces().filter(f => !f.equals(face)),
        'numSides',
      );
      return (
        _.isEqual(faceCounts, { '4': face.numSides }) ||
        _.isEqual(faceCounts, { '3': 2 * face.numSides })
      );
    }),
    'numSides',
  );
  if (!face1) return undefined;

  const face2 = _.find(
    polyhedron.faces,
    face2 =>
      face1.numSides === face2.numSides &&
      isInverse(face1.normal(), face2.normal()),
  );
  if (face2) return [face1, face2];
  return undefined;
}
开发者ID:tessenate,项目名称:polyhedra-viewer,代码行数:25,代码来源:prismUtils.ts

示例9: getMaxColumn

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

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

示例10: resolve

 return new Promise<IExam>((resolve, reject) => {
   var id = _.maxBy(self.datasource, 'id')['id'] + 1;
   record.id = id;
   self.datasource.push(record);
   self.data[record.id.toString()] = record;
   resolve(record);
 });
开发者ID:Matrixbirds,项目名称:corona,代码行数:7,代码来源:adapter.ts


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