本文整理汇总了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);
});
示例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);
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}
示例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 });
})