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


TypeScript lodash.minBy函数代码示例

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


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

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

示例2: paintShortestPath

    public paintShortestPath() {
        /*let node = this.map.getGoalCell().previous;
        while (node !== undefined) {
          if (node.isVisited) {
            node.type = CellType.Current;
            node.color = undefined;
          }
          node = node.previous;
        }*/
        let start = this.map.getStartCell();
        let node = this.map.getGoalCell();
        let nodeDistance = (cell: Cell) => cell.distance;
        do {
            let predecessors =
                this.getNeighbors(node, (cell: Cell) => !cell.isBlocked)
                    .filter(node => Number.isFinite(node.distance));

            if (predecessors.length === 0) { // deadend
                console.log("path is blocked");
                break;
            }

            node = _.minBy(predecessors, nodeDistance);
            if (node.isVisited) {
                node.type = CellType.Current;
                node.color = undefined;
            }
            // console.log("paint node"+ node.toString());
        } while (node !== start);
    }
开发者ID:oliverguhr,项目名称:pathsim,代码行数:30,代码来源:PathAlgorithm.ts

示例3: step

    public step() {
        let isRunning = true;
        let currentCell = _.minBy(this.cells, c => c.distance);

        if (currentCell.isGoal) {
            this.paintShortestPath();
            return false;
        }

        _.pull(this.cells, currentCell);

        let neighbors = this.getNeighbors(currentCell, (cell: Cell) => !cell.isBlocked && !cell.isVisited);

        for (let neighbor of neighbors) {
            if (isRunning) {
                this.updateDistance(currentCell, neighbor);
            }
            if (neighbor.isGoal) {
                this.paintShortestPath();
                isRunning = false;
                break;
            }
        }
        return isRunning;
    }
开发者ID:oliverguhr,项目名称:pathsim,代码行数:25,代码来源:Dijkstra.ts

示例4: mapMetricsToColors

export function mapMetricsToColors(
    IdMetricMap: any, metricKeyData: MetricKeyData): Map<string, Uint64> {
  let colors = ['Yellow', 'aquamarine', 'deepskyblue', 'mediumorchid'];
  let metricIteratee = function(el: ArrayLike<number>) {
    return el[1];  // metric value
  };
  let min = metricKeyData.min = minBy(IdMetricMap, metricIteratee)![1];
  let max = metricKeyData.max = maxBy(IdMetricMap, metricIteratee)![1];
  let scale = metricKeyData.chromaScale = chroma!.scale(colors).domain([min, max]);

  for (let i = 0, len = IdMetricMap.length; i < len; i++) {
    let metricArr = IdMetricMap[i];
    let metricVal = metricArr[1];
    let rgb = (scale(metricVal)).rgba();
    // convert color to 32bit little-endian value
    metricArr[1] = (rgb[3] << 24) + (rgb[2] << 16) + (rgb[1] << 8) + rgb[0];
    // make data key
    let idUint64 = new Uint64();
    idUint64.parseString(metricArr[0].toString());
    metricArr[0] = idUint64.low + ',' + idUint64.high;
    // convert val to Uint64 with rand high values
    let randHigh = Math.floor(Math.random() * Math.pow(2, 32));
    metricArr[1] = new Uint64(metricArr[1], randHigh);
  }
  metricKeyData.IDColorMap = new Map<string, Uint64>(IdMetricMap);
  return metricKeyData.IDColorMap;
}
开发者ID:janelia-flyem,项目名称:neuroglancer,代码行数:27,代码来源:metric_color_util.ts

示例5: getSnubAngle

export function getSnubAngle(polyhedron: Polyhedron, faces: Face[]) {
  const [face0, ...rest] = faces;
  const faceCentroid = face0.centroid();
  const faceNormal = face0.normal();
  const midpoint = face0.edges[0].midpoint();

  const face1 = _.minBy(rest, face => midpoint.distanceTo(face.centroid()))!;

  const plane = getPlane([
    faceCentroid,
    face1.centroid(),
    polyhedron.centroid(),
  ]);

  const normMidpoint = midpoint.sub(faceCentroid);
  const projected = plane.getProjectedPoint(midpoint).sub(faceCentroid);
  const angle = normMidpoint.angleBetween(projected, true) || 0;
  // Return a positive angle if it's a ccw turn, a negative angle otherwise
  const sign = normMidpoint
    .cross(projected)
    .getNormalized()
    .equalsWithTolerance(faceNormal, PRECISION)
    ? -1
    : 1;
  return angle * sign;
}
开发者ID:tessenate,项目名称:polyhedra-viewer,代码行数:26,代码来源:resizeUtils.ts

示例6: step

    public step() {
        let path = this.map.cells.filter(cell => cell.isCurrent && cell.distance > this.currentDistance);
        let nextCell = _.minBy(path, cell => cell.distance);

        if (nextCell === undefined) {
            return;
        }
        this.robot.moveTo(nextCell.position);
        this.currentDistance = nextCell.distance;
    }
开发者ID:oliverguhr,项目名称:pathsim,代码行数:10,代码来源:Robot.ts

示例7:

 makeRoomBuckets.forEach((makeRoomBucket) => {
   const items = store.buckets[makeRoomBucket.id];
   if (items.length > 0 && items.length >= makeRoomBucket.capacity) {
     // We'll move the lowest-value item to the vault.
     const itemToMove = _.minBy(items.filter((i) => !i.equipped && !i.notransfer), (i) => {
       let value = {
         Common: 0,
         Uncommon: 1,
         Rare: 2,
         Legendary: 3,
         Exotic: 4
       }[i.tier];
       // And low-stat
       if (i.primStat) {
         value += i.primStat.value / 1000;
       }
       return value;
     });
     if (itemToMove) {
       itemsToMove.push(itemToMove);
     }
   }
 });
开发者ID:w1cked,项目名称:DIM,代码行数:23,代码来源:d2farming.service.ts

示例8:

 return targetLanguages.map(r => _.minBy(r.names, s => s.length)).join("|");
开发者ID:nrkn,项目名称:quicktype,代码行数:1,代码来源:index.ts

示例9: buildTalentGrid


//.........这里部分代码省略.........

      // hacky way to determine if the node is a weapon ornament
      let ornamentComplete = false;
      if (talentNodeGroup.column > 1 && !xpRequired && !exclusiveInColumn && item.primaryStat) {
        ornamentComplete = node.isActivated;
      }

      // There's a lot more here, but we're taking just what we need
      return {
        name: nodeName,
        ornament: ornamentComplete,
        hash: talentNodeSelected.nodeStepHash,
        description: talentNodeSelected.nodeStepDescription,
        icon: talentNodeSelected.icon,
        // XP put into this node
        xp,
        // XP needed for this node to unlock
        xpRequired,
        // Position in the grid
        column: talentNodeGroup.column,
        row: talentNodeGroup.row,
        // Is the node selected (lit up in the grid)
        activated: node.isActivated,
        // The item level at which this node can be unlocked
        activatedAtGridLevel,
        // Only one node in this column can be selected (scopes, etc)
        exclusiveInColumn,
        // Whether there's enough XP in the item to buy the node
        xpRequirementMet: activatedAtGridLevel <= totalLevel,
        // Whether or not the material cost has been paid for the node
        unlocked,
        // Some nodes don't show up in the grid, like purchased ascend nodes
        hidden: node.hidden,

        dtrHash,
        dtrRoll

        // Whether (and in which order) this perk should be
        // "featured" on an abbreviated info panel, as in the
        // game. 0 = not featured, positive numbers signify the
        // order of the featured perks.
        // featuredPerk: (featuredPerkNames.indexOf(nodeName) + 1)

        // This list of material requirements to unlock the
        // item are a mystery. These hashes don't exist anywhere in
        // the manifest database. Also, the activationRequirement
        // object doesn't say how much of the material is
        // needed. There's got to be some missing DB somewhere with
        // this info.
        // materialsNeeded: talentNodeSelected.activationRequirement.materialRequirementHashes

        // These are useful for debugging or searching for new properties,
        // but they don't need to be included in the result.
        // talentNodeGroup: talentNodeGroup,
        // talentNodeSelected: talentNodeSelected,
        // itemNode: node
      };
    }
  ) as D1GridNode[];

  // We need to unique-ify because Ornament nodes show up twice!
  gridNodes = _.uniqBy(_.compact(gridNodes), (n) => n.hash);

  if (!gridNodes.length) {
    return null;
  }

  // This can be handy for visualization/debugging
  // var columns = _.groupBy(gridNodes, 'column');

  const maxLevelRequired = _.maxBy(gridNodes, (n: any) => n.activatedAtGridLevel)
    .activatedAtGridLevel;
  const totalXPRequired = xpToReachLevel(maxLevelRequired);

  const ascendNode: any = _.find(gridNodes, { hash: 1920788875 });

  // Fix for stuff that has nothing in early columns
  const minColumn = _.minBy(_.reject(gridNodes, (n: any) => n.hidden), (n: any) => n.column).column;
  if (minColumn > 0) {
    gridNodes.forEach((node) => {
      node.column -= minColumn;
    });
  }
  const maxColumn = _.maxBy(gridNodes, (n: any) => n.column).column;

  return {
    nodes: _.sortBy(gridNodes, (node) => node.column + 0.1 * node.row),
    xpComplete: totalXPRequired <= totalXP,
    totalXPRequired,
    totalXP: Math.min(totalXPRequired, totalXP),
    hasAscendNode: Boolean(ascendNode),
    ascended: Boolean(ascendNode && ascendNode.activated),
    infusable: gridNodes.some((n) => n.hash === 1270552711),
    dtrPerks: _.compact(gridNodes.map((i) => i.dtrHash)).join(';'),
    dtrRoll: _.compact(gridNodes.map((i) => i.dtrRoll)).join(';'),
    complete:
      totalXPRequired <= totalXP &&
      _.every(gridNodes, (n: any) => n.unlocked || (n.xpRequired === 0 && n.column === maxColumn))
  };
}
开发者ID:w1cked,项目名称:DIM,代码行数:101,代码来源:d1-item-factory.service.ts

示例10: buildTalentGrid

function buildTalentGrid(
  item: DestinyItemComponent,
  talentsMap: { [key: string]: DestinyItemTalentGridComponent },
  talentDefs: LazyDefinition<DestinyTalentGridDefinition>
): DimTalentGrid | null {
  if (!item.itemInstanceId || !talentsMap[item.itemInstanceId]) {
    return null;
  }
  const talentGrid = talentsMap[item.itemInstanceId];
  if (!talentGrid) {
    return null;
  }

  const talentGridDef = talentDefs.get(talentGrid.talentGridHash);
  if (!talentGridDef || !talentGridDef.nodes || !talentGridDef.nodes.length) {
    return null;
  }

  const gridNodes = _.compact(
    talentGrid.nodes.map(
      (node): DimGridNode | undefined => {
        const talentNodeGroup = talentGridDef.nodes[node.nodeIndex];
        const talentNodeSelected = talentNodeGroup.steps[0];

        if (!talentNodeSelected) {
          return undefined;
        }

        const nodeName = talentNodeSelected.displayProperties.name;

        // 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.exclusiveWithNodeHashes &&
            talentNodeGroup.exclusiveWithNodeHashes.length > 0
        );

        const activatedAtGridLevel = talentNodeSelected.activationRequirement.gridLevel;

        // There's a lot more here, but we're taking just what we need
        return {
          name: nodeName,
          hash: talentNodeSelected.nodeStepHash,
          description: talentNodeSelected.displayProperties.description,
          icon: talentNodeSelected.displayProperties.icon,
          // Position in the grid
          column: talentNodeGroup.column / 8,
          row: talentNodeGroup.row / 8,
          // Is the node selected (lit up in the grid)
          activated: node.isActivated,
          // The item level at which this node can be unlocked
          activatedAtGridLevel,
          // Only one node in this column can be selected (scopes, etc)
          exclusiveInColumn,
          // Whether or not the material cost has been paid for the node
          unlocked: true,
          // Some nodes don't show up in the grid, like purchased ascend nodes
          hidden: node.hidden
        };
      }
    )
  );

  if (!gridNodes.length) {
    return null;
  }

  // Fix for stuff that has nothing in early columns
  const minByColumn = _.minBy(gridNodes.filter((n) => !n.hidden), (n) => n.column)!;
  const minColumn = minByColumn.column;
  if (minColumn > 0) {
    gridNodes.forEach((node) => {
      node.column -= minColumn;
    });
  }

  return {
    nodes: _.sortBy(gridNodes, (node) => node.column + 0.1 * node.row),
    complete: gridNodes.every((n) => n.unlocked)
  };
}
开发者ID:w1cked,项目名称:DIM,代码行数:85,代码来源:d2-item-factory.service.ts


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