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


TypeScript underscore.shuffle函數代碼示例

本文整理匯總了TypeScript中underscore.shuffle函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript shuffle函數的具體用法?TypeScript shuffle怎麽用?TypeScript shuffle使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了shuffle函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: it

      it('correctly sorts parents', () => {
        const numberOfParents = simulateQueryData.results.categoryFacets[0].parentValues.length - 1;
        simulateQueryData.results.categoryFacets[0].values = [];
        simulateQueryData.results.categoryFacets[0].parentValues = shuffle(simulateQueryData.results.categoryFacets[0].parentValues);

        Simulate.query(test.env, simulateQueryData);

        verifyParents(numberOfParents);
      });
開發者ID:francoislg,項目名稱:search-ui,代碼行數:9,代碼來源:CategoryFacetTest.ts

示例2: topCardsOfDeck

    // May trigger a shuffle
    topCardsOfDeck(game: Game, n: number) : CardInPlay[] {
        if (this.deck.count < n) {
            const reorderedDiscard = _.shuffle<CardInPlay>(this.discard.cards);
            game.moveCardsToBottom(reorderedDiscard, this.deck);

            game.log(`${this.name} shuffles`);
        }

        return _.last(this.deck.cards, n);
    }
開發者ID:scottostler,項目名稱:conspirator,代碼行數:11,代碼來源:player.ts

示例3: modifyAddDuplicateLetters

function modifyAddDuplicateLetters(name: string): string {
    let lengthAvailable = characterConfig.MAX_NAME_LENGTH - name.length;
    const duplicationLetters: string[] = _.shuffle(DUPLICATION_LETTERS);
    for (let letter of duplicationLetters) {
        if (lengthAvailable > 0 && faker.random.boolean()) {
            name = name.replace(letter, letter + letter);
            lengthAvailable = characterConfig.MAX_NAME_LENGTH - name.length;
        }
    }
    return name;
}
開發者ID:Tzook,項目名稱:lul,代碼行數:11,代碼來源:randomNames.ts

示例4: findNewcomers

 private async findNewcomers(current:DBBlock, filteringFunc: (joinData: { [pub:string]: any }) => Promise<{ [pub:string]: any }>) {
   const updates = {};
   const preJoinData = await this.getPreJoinData(current);
   const joinData = await filteringFunc(preJoinData);
   const members = await this.dal.getMembers();
   const wotMembers = _.pluck(members, 'pubkey');
   // Checking step
   let newcomers = _(joinData).keys();
   newcomers = _.shuffle(newcomers)
   const nextBlockNumber = current ? current.number + 1 : 0;
   try {
     const realNewcomers = await this.iteratedChecking(newcomers, async (someNewcomers:string[]) => {
       const nextBlock = {
         number: nextBlockNumber,
         joiners: someNewcomers,
         identities: _.filter(newcomers.map((pub:string) => joinData[pub].identity), { wasMember: false }).map((idty:any) => idty.pubkey)
       };
       const theNewLinks = await this.computeNewLinks(nextBlockNumber, someNewcomers, joinData, updates)
       await this.checkWoTConstraints(nextBlock, theNewLinks, current);
     })
     const newLinks = await this.computeNewLinks(nextBlockNumber, realNewcomers, joinData, updates);
     const newWoT = wotMembers.concat(realNewcomers);
     const finalJoinData: { [pub:string]: any } = {};
     realNewcomers.forEach((newcomer:string) => {
       // Only keep membership of selected newcomers
       finalJoinData[newcomer] = joinData[newcomer];
       // Only keep certifications from final members
       const keptCerts:any[] = [];
       joinData[newcomer].certs.forEach((cert:any) => {
         const issuer = cert.from;
         if (~newWoT.indexOf(issuer) && ~newLinks[cert.to].indexOf(issuer)) {
           keptCerts.push(cert);
         }
       });
       joinData[newcomer].certs = keptCerts;
     });
     return {
       current: current,
       newWotMembers: wotMembers.concat(realNewcomers),
       finalJoinData: finalJoinData,
       updates: updates
     }
   } catch(err) {
     this.logger.error(err);
     throw err;
   }
 }
開發者ID:Kalmac,項目名稱:duniter,代碼行數:47,代碼來源:blockGenerator.ts

示例5: getMaxRepeatValue

export function getMaxRepeatValue (arr: Array<string>): string {
    var obj: MaxRepeatObject = {
        max: {
            count: 0, 
            value: ''
        }
    };

    _.shuffle(arr).forEach((val: string) => {
        obj[val] = obj[val] || 0;
        obj[val]++;
        
        if(obj[val] > obj.max.count) {
            obj.max.count = obj[val];
            obj.max.value = val;
        }
    });
    
    return obj.max.value;
}
開發者ID:andreevWork,項目名稱:mafia,代碼行數:20,代碼來源:helpers.ts

示例6: RolesForPlayers

    export function RolesForPlayers(players: Array<Player>): Array<GamePlayer>{
        let steps: number = Math.floor((players.length - MIN_PLAYERS) / STEP_CHANGE_ROLES) + 1,
            game_players: Array<GamePlayer> = _.shuffle(players).map((player: Player) => _.extend({role: Roles.INHABITANT}, player)),
            flag_commissar = false,
            index: number = 0;

        game_players[index++].role = Roles.DOCTOR;
        game_players[index++].role = Roles.WHORE;

        while(steps--) {
            game_players[index++].role = Roles.MAFIA;

            if(steps % 2 !== 0) {
                if(!flag_commissar) {
                    game_players[index++].role = Roles.COMMISSAR;
                    flag_commissar = true;
                }
            }
        }

        return game_players;
    }
開發者ID:andreevWork,項目名稱:mafia,代碼行數:22,代碼來源:Player.ts

示例7:

                .then(sourceItems => {
                    console.log("got all source's items", {sourceItems});
                    // sourceItems = sourceItems.map(items => items.slice(0, 5));
                    var candidateItems = _.flatten(sourceItems);

                    // take all the items returned by Python, check each to see if it's been
                    // colourised already, build a new array (to return to user) with those
                    var allItems = [];
                    candidateItems.forEach(item => {
                        const hash = crypto.createHash('md5');
                        hash.update(item.originalImageUrl);
                        const outputFile = hash.digest('hex') + '.jpg';

                        if (alreadyProcessedFiles[outputFile]) {
                            allItems.push(item);
                        }
                    });

                    console.log("flattened items", {allItems});
                    allItems = _.shuffle(allItems);
                    console.log("shuffled items", {allItems});
                    res.json({ items: allItems });
                })
開發者ID:colourful-past,項目名稱:website,代碼行數:23,代碼來源:WebHandler.ts


注:本文中的underscore.shuffle函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。