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


TypeScript underscore.countBy函数代码示例

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


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

示例1: it

        it(`тест с числом игроков равным ${count_players}`, () => {
            // Создаем массив с игроками
            players = Array.apply(null, {length: count_players}).map(() => getPlayer());

            // Отправляем в тестируемую функцию
            game_players = Player.RolesForPlayers(players);

            // По приходу из коллекции игроков, забираем у каждого его роль и суем в массив
            roles_array = _.pluck(game_players, 'role');

            // Затем считаем, сколько пришлось игроков на каждую роль
            count_roles = _.countBy(roles_array, _.identity);

            // Поскольку данные персонажи есть не всегда, надо явно проставить ноль для сравнения
            count_roles[Roles.COMMISSAR] = count_roles[Roles.COMMISSAR] || 0;
            count_roles[Roles.WHORE] = count_roles[Roles.WHORE] || 0;

            mafia_count = Math.floor((count_players - MIN_PLAYERS) / STEP_CHANGE_ROLES) + 1;
            doctor_count = 1;
            whore_count = 1;
            commissar_count = count_players >= MIN_PLAYERS + STEP_CHANGE_ROLES ? 1 : 0;

            expect(count_roles[Roles.MAFIA]).toBe(mafia_count);
            expect(count_roles[Roles.DOCTOR]).toBe(doctor_count);
            expect(count_roles[Roles.COMMISSAR]).toBe(commissar_count);
            expect(count_roles[Roles.WHORE]).toBe(whore_count);
            expect(count_roles[Roles.INHABITANT]).toBe(count_players - mafia_count - doctor_count - commissar_count - whore_count);
        });
开发者ID:andreevWork,项目名称:mafia,代码行数:28,代码来源:PlayerTest.ts

示例2: moveItemsToVault

// cribbed from dimFarmingService, but modified
async function moveItemsToVault(
  storeService: StoreServiceType,
  store: DimStore,
  items: DimItem[],
  dimItemService
): Promise<void> {
  const reservations = {};
  // reserve space for all move-asides
  reservations[store.id] = _.countBy(items, 'type');

  for (const item of items) {
    // Move a single item. We reevaluate the vault each time in case things have changed.
    const vault = storeService.getVault();
    const vaultSpaceLeft = vault!.spaceLeftForItem(item);
    if (vaultSpaceLeft <= 1) {
      // If we're down to one space, try putting it on other characters
      const otherStores = storeService.getStores().filter((store) => !store.isVault && store.id !== store.id);
      const otherStoresWithSpace = otherStores.filter((store) => store.spaceLeftForItem(item));

      if (otherStoresWithSpace.length) {
        await dimItemService.moveTo(item, otherStoresWithSpace[0], false, item.amount, items, reservations);
        continue;
      }
    }
    await dimItemService.moveTo(item, vault, false, item.amount, items, reservations);
  }
}
开发者ID:delphiactual,项目名称:DIM,代码行数:28,代码来源:postmaster.ts

示例3: bucketsService

  return bucketsService().then((buckets) => {
    const postmasterItems: DimItem[] = flatMap(
      buckets.byCategory.Postmaster,
      (bucket: InventoryBucket) => store.buckets[bucket.id]
    );
    const postmasterItemCountsByType = _.countBy(postmasterItems, (i) => i.bucket.id);

    // If any category is full, we'll move enough aside
    const itemsToMove: DimItem[] = [];
    _.each(postmasterItemCountsByType, (count, bucket) => {
      if (count > 0) {
        const items: DimItem[] = store.buckets[bucket];
        const capacity = store.capacityForItem(items[0]);
        const numNeededToMove = Math.max(0, count + items.length - capacity);
        if (numNeededToMove > 0) {
          // We'll move the lowest-value item to the vault.
          const candidates = _.sortBy(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;
          });
          itemsToMove.push(..._.first(candidates, numNeededToMove));
        }
      }
    });

    // TODO: it'd be nice if this were a loadout option
    return moveItemsToVault(store.getStoresService(), store, itemsToMove, dimItemService)
      .then(() => {
        toaster.pop(
          'success',
          t('Loadouts.MakeRoom'),
          t('Loadouts.MakeRoomDone', {
            count: postmasterItems.length,
            movedNum: itemsToMove.length,
            store: store.name,
            context: store.gender
          })
        );
      })
      .catch((e) => {
        toaster.pop(
          'error',
          t('Loadouts.MakeRoom'),
          t('Loadouts.MakeRoomError', { error: e.message })
        );
        throw e;
      }) as IPromise<void>;
  });
开发者ID:bhollis,项目名称:DIM,代码行数:58,代码来源:postmaster.ts

示例4: expect

        unsubscribe = store.subscribe(() => {
            expect(store.getState().status).toBe(GameStatus.START_THE_GAME);

            let count = _.countBy(store.getState().players, player => {
                return player.role;
            });

            expect(count[Roles.INHABITANT]).toBe(3);
            expect(count[Roles.DOCTOR]).toBe(1);
            expect(count[Roles.WHORE]).toBe(1);
            expect(count[Roles.MAFIA]).toBe(1);
            
            // Отписываемся т. к. store общий для всех тестов
            unsubscribe();
            done();
        });
开发者ID:andreevWork,项目名称:mafia,代码行数:16,代码来源:FirstScenario.ts

示例5: function

        var uniqContact = function(args){
            args.HasError = false;
            args.ErrorMessage = "";
            var fullNames =_.map(this.Contacts,function(contact:any){return contact.Email});
            var itemcounts = _.countBy(fullNames, function (n) { return n; });
            var dupes = _.reduce(itemcounts, function (memo:Array<string>, item, idx) {
                if (item > 1)
                    memo.push(idx);
                return memo;
            }, []);

            if (dupes.length != 0) {
                args.HasError = true;
                args.ErrorMessage =  _.reduce(dupes, function (memo:string, fullName:string) {
                    return memo + fullName + " ";
                },"Each contact must be unique. Not unique values: ");

                return;
            }
        };
开发者ID:rsamec,项目名称:business-rules-engine,代码行数:20,代码来源:rulesShared.ts

示例6: init

function init() {
	const count = countBy(TITLE_DEFAULT, (t) => t.title);
	for (const c in count) {
		if (c in count && count[c] > 1) {
			throw `称谓重复: ${c}`;
		}
	}
	for (const t of TITLE_DEFAULT) {
		if (!t.son) {
			throw `${t.title}缺少儿子称谓`;
		}
		if (!t.daughter) {
			throw `${t.title}缺少女儿称谓`;
		}
		if (t.son && t.son.title) {
			t.son.compare = '';
		}
		if (t.daughter && t.daughter.title) {
			t.daughter.compare = '';
		}
	}
}
开发者ID:xuender,项目名称:family,代码行数:22,代码来源:title.ts


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