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

TypeScript underscore.groupBy函数代码示例

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

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



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

示例1: optimalLoadout

export function optimalLoadout(applicableItems: DimItem[], bestItemFn: (item: DimItem) => number, name: string): Loadout {
  const itemsByType = _.groupBy(applicableItems, 'type');

  // Pick the best item
  let items = _.mapObject(itemsByType, (items) => _.max(items, bestItemFn));

  // Solve for the case where our optimizer decided to equip two exotics
  const getLabel = (i) => i.equippingLabel;
  // All items that share an equipping label, grouped by label
  const overlaps: _.Dictionary<DimItem[]> = _.groupBy(Object.values(items).filter(getLabel), getLabel);
  _.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;
    }
  });

  // Copy the items and mark them equipped and put them in arrays, so they look like a loadout
  const finalItems: { [type: string]: DimItem[] } = {};
  _.each(items, (item, type) => {
    const itemCopy = copy(item);
    itemCopy.equipped = true;
    finalItems[type.toLowerCase()] = [itemCopy];
  });

  return {
    classType: -1,
    name,
    items: finalItems
  };
}
开发者ID:delphiactual,项目名称:DIM,代码行数:60,代码来源:loadout-utils.ts


示例2: getSetTiers

export function getSetTiers(armorSets: ArmorSet[]): string[] {
  const tiersSet = new Set<string>();
  armorSets.forEach((set: ArmorSet) => {
    set.tiers.forEach((tier: string) => {
      tiersSet.add(tier);
    });
  });

  const tiers = _.each(
    _.groupBy(Array.from(tiersSet.keys()), (tierString: string) => {
      return sum(tierString.split('/'), (num) => parseInt(num, 10));
    }),
    (tier) => {
      tier.sort().reverse();
    }
  );

  const tierKeys = Object.keys(tiers);
  const setTiers: string[] = [];
  for (let tier = tierKeys.length; tier > tierKeys.length - 3; tier--) {
    if (tierKeys[tier]) {
      setTiers.push(t('LoadoutBuilder.SelectTierHeader', { tier: tierKeys[tier] }));
      tiers[tierKeys[tier]].forEach((set) => {
        setTiers.push(set);
      });
    }
  }

  return setTiers;
}
开发者ID:bhollis,项目名称:DIM,代码行数:30,代码来源:utils.ts


示例3: function

    cloudThis: function (objectList, idProp, keyProp, textProp, options) {
        let exclude = options.exclude || [];
        let topN = options.topN || 50;
        let minCount = options.minCount || 1;
        let descFinder = options.descriptions || function () { return null; };

        var plaqueLists = _.groupBy(objectList, (o) => {
            return o[keyProp];
        });

        let toplist = _.map(Object.keys(plaqueLists), function (key) {
            var tags = analyseArray(plaqueLists[key]);
            let words = _(Object.keys(tags))
                .filter((w) => exclude.indexOf(w) === -1)
                .map((w) => {
                    return {
                        word: w,
                        plaques: _.uniq(tags[w], (t) => t.id)
                    };
                })
                .filter((w) => w.plaques.length > minCount);

            let sorted = _.sortBy(words, (w) => w.plaques.length * -1);
            let top10 = _.first(sorted, topN);

            return {
                key: key,
                words: top10,
                description: descFinder(key)
            };
        });

        return toplist;
    }
开发者ID:toastermagic,项目名称:plaques,代码行数:34,代码来源:index.ts


示例4: gatherTokensLoadout

export function gatherTokensLoadout(storeService: StoreServiceType): Loadout {
  let tokens = storeService.getAllItems().filter((i) => {
    return REP_TOKENS.has(i.hash) && !i.notransfer;
  });

  if (tokens.length === 0) {
    throw new Error(t('Loadouts.NoTokens'));
  }

  tokens = addUpStackables(tokens);

  const itemsByType = _.groupBy(tokens, 'type');

  // Copy the items and put them in arrays, so they look like a loadout
  const finalItems = {};
  _.each(itemsByType, (items, type) => {
    if (items) {
      finalItems[type.toLowerCase()] = items;
    }
  });

  return {
    classType: -1,
    name: t('Loadouts.GatherTokens'),
    items: finalItems
  };
}
开发者ID:delphiactual,项目名称:DIM,代码行数:27,代码来源:auto-loadouts.ts


示例5: searchLoadout

export function searchLoadout(storeService: StoreServiceType, store: DimStore): Loadout {
  let items = storeService.getAllItems().filter((i) => {
    return i.visible &&
      !i.location.inPostmaster &&
      !i.notransfer;
  });

  items = addUpStackables(items);

  const itemsByType = _.mapObject(_.groupBy(items, 'type'), (items) => limitToBucketSize(items, store.isVault));

  // Copy the items and mark them equipped and put them in arrays, so they look like a loadout
  const finalItems = {};
  _.each(itemsByType, (items, type) => {
    if (items) {
      finalItems[type.toLowerCase()] = items.map((i) => {
        const copiedItem = copy(i);
        copiedItem.equipped = false;
        return copiedItem;
      });
    }
  });

  return {
    classType: -1,
    name: t('Loadouts.FilteredItems'),
    items: finalItems
  };
}
开发者ID:delphiactual,项目名称:DIM,代码行数:29,代码来源:auto-loadouts.ts


示例6:

    ).then((items) => {
      store.items = items;

      // by type-bucket
      store.buckets = _.groupBy(items, (i) => i.location.id);

      store.vaultCounts = {};

      // Fill in any missing buckets
      Object.values(buckets.byType).forEach((bucket) => {
        if (!store.buckets[bucket.id]) {
          store.buckets[bucket.id] = [];
        }

        if (bucket.vaultBucket) {
          const vaultBucketId = bucket.vaultBucket.id;
          store.vaultCounts[vaultBucketId] = store.vaultCounts[vaultBucketId] || {
            count: 0,
            bucket: bucket.accountWide ? bucket : bucket.vaultBucket
          };
          store.vaultCounts[vaultBucketId].count += store.buckets[bucket.id].length;
        }
      });

      return store;
    });
开发者ID:bhollis,项目名称:DIM,代码行数:26,代码来源:d2-stores.service.ts


示例7: constructor

	constructor(private navCtrl: NavController) {
		this.titles = [];
		const g = groupBy(TITLE_DEFAULT, (t) => t.classify);
		for (const c in g) {
			if (c in g) {
				this.titles.push([c, g[c]]);
			}
		}
	}
开发者ID:xuender,项目名称:family,代码行数:9,代码来源:title-list.ts


示例8: addUpStackables

// Add up stackable items so we don't have duplicates. This helps us actually move them, see
// https://github.com/DestinyItemManager/DIM/issues/2691#issuecomment-373970255
function addUpStackables(items: DimItem[]) {
  return flatMap(Object.values(_.groupBy(items, (t) => t.hash)), (items) => {
    if (items[0].maxStackSize > 1) {
      const item = copy(items[0]);
      item.amount = sum(items, (i) => i.amount);
      return [item];
    } else {
      return items;
    }
  });
}
开发者ID:delphiactual,项目名称:DIM,代码行数:13,代码来源:auto-loadouts.ts


示例9: processItems

    return processItems(store, items, itemComponents, previousItems, newItems, itemInfoService).then((items) => {
      store.items = items;

      // by type-bucket
      store.buckets = _.groupBy(items, (i) => {
        return i.location.id;
      });

      // Fill in any missing buckets
      Object.values(buckets.byType).forEach((bucket) => {
        if (!store.buckets[bucket.id]) {
          store.buckets[bucket.id] = [];
        }
      });

      return store;
    });
开发者ID:delphiactual,项目名称:DIM,代码行数:17,代码来源:d2-stores.service.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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