本文整理汇总了TypeScript中lodash.shuffle函数的典型用法代码示例。如果您正苦于以下问题:TypeScript shuffle函数的具体用法?TypeScript shuffle怎么用?TypeScript shuffle使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了shuffle函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: test
test('arrangeLessonsWithinDay', () => {
// Empty array.
const arrangement0: TimetableDayArrangement = arrangeLessonsWithinDay([]);
expect(arrangement0.length).toBe(1);
// Can fit within one row.
const arrangement1: TimetableDayArrangement = arrangeLessonsWithinDay(
_.shuffle([
createGenericColoredLesson('Monday', '1000', '1200'),
createGenericColoredLesson('Monday', '1600', '1800'),
createGenericColoredLesson('Monday', '1400', '1500'),
]),
);
expect(arrangement1.length).toBe(1);
// Two rows.
const arrangement2: TimetableDayArrangement = arrangeLessonsWithinDay(
_.shuffle([
createGenericColoredLesson('Monday', '1000', '1200'),
createGenericColoredLesson('Monday', '1600', '1800'),
createGenericColoredLesson('Monday', '1500', '1700'),
]),
);
expect(arrangement2.length).toBe(2);
// Three rows.
const arrangement3: TimetableDayArrangement = arrangeLessonsWithinDay(
_.shuffle([
createGenericColoredLesson('Monday', '1000', '1200'),
createGenericColoredLesson('Monday', '1100', '1300'),
createGenericColoredLesson('Monday', '1000', '1300'),
]),
);
expect(arrangement3.length).toBe(3);
});
示例2: match
match (killers): string[] {
let k = _.shuffle(killers);
k[k.length - 1].person = _.pick(k[0], ['name', 'word', 'uuid']);
let i;
for (i = 0; i < k.length - 1; i++) {
k[i].person = _.pick(k[i + 1], ['name', 'word', 'uuid']);
}
return _.shuffle(k);
}
示例3: timelineSeries
timelineSeries(count = 8) {
const offsets = shuffle(times(count, (index) => index));
const labels = [['Confort', 'icon-bed'],
['Eco', 'icon-leaf'],
['Night', 'icon-moon'],
['Game', 'icon-gamepad'],
['Recreation', 'icon-keyboard'],
['Visit', 'icon-stethoscope'],
['Work', 'icon-briefcase'],
['Shopping', 'icon-shopping-bag']];
return times(count, (index) => {
const offset = offsets.pop();
const title = labels.pop();
const date = new Date().getTime();
const seeek = random(-72, 72);
const begin = date + (seeek * 10000);
return {
data: this.getDataSeries(begin, offset),
lineWidth: 10,
name: {
title: title[0],
icon: title[1]
}
};
});
}
示例4: generateCards
generateCards(eachSuitNumber:number, suits:Suit[]):Card[] {
let cards = [];
suits.forEach((suit)=> {
_.times(eachSuitNumber, (n)=> {
cards.push(new Card(suit, n + 1));
});
});
return _.shuffle(cards);
}
示例5: executeRequestsFlow
private static async executeRequestsFlow({
requests,
concurrency = 1,
toShuffle = true,
}: {
requests: Array<() => any>;
concurrency?: number;
toShuffle?: boolean;
}) {
if (toShuffle) {
requests = shuffle(requests);
}
await Bluebird.map(requests, request => request(), { concurrency });
}
示例6: enabler
"!scramble": enabler((command: Tennu.Command) => {
var cache = scrambleCache[command.channel] = scrambleCache[command.channel] || { running: false };
if (cache.running) {
return "A game is still running. Unsramble this name: " + cache.scrambled;
} else {
(runningCache[command.channel] = runningCache[command.channel] || []).push("scramble")
var name = _.sample(Data.pokemon_array).name;
cache = scrambleCache[command.channel] = {
running: true,
name: name,
scrambled: _.shuffle(name.toUpperCase()).join(" "),
end: moment()
}
cache.end.add(3, "m")
return "Unscramble this name: " + cache.scrambled;
}
}),
示例7: initialize
static initialize(): Paiyama {
let pais = [
// manzu
new Manzu(1), new Manzu(2), new Manzu(3), new Manzu(4), new Manzu(5),
new Manzu(6), new Manzu(7), new Manzu(8), new Manzu(9),
// pinzu
new Pinzu(1), new Pinzu(2), new Pinzu(3), new Pinzu(4), new Pinzu(5),
new Pinzu(6), new Pinzu(7), new Pinzu(8), new Pinzu(9),
// souzu
new Souzu(1), new Souzu(2), new Souzu(3), new Souzu(4), new Souzu(5),
new Souzu(6), new Souzu(7), new Souzu(8), new Souzu(9),
// jihai
Jihai.TON, Jihai.NAN, Jihai.SHA, Jihai.PEI,
Jihai.HAKU, Jihai.HATSU, Jihai.TYUN
];
// 全種類を4つづつ
let allPais = lodash.flatMap(Array(4), () => pais);
// ランダムに並び替え
return new Paiyama(lodash.shuffle(allPais));
}
示例8:
_.each(nodesByGroup, (nodes: Node[], groupName: string) => {
// Clone list to preserve the original data, do Fisher-Yates shuffle
var shuffled: Node[] = _.shuffle(_.cloneDeep(nodes));
// Progressively add nodes to circle or recompute circle
var circle: NodeGroupCircle = null;
for (let i: number = 0; i < shuffled.length; i++) {
let node: Node = shuffled[i];
if (circle === null || !this._isInCircle(circle, node)) {
circle = this._makeCircleOneNode(_.slice(shuffled, 0, i + 1), node);
}
}
if (circle === null) {
return;
}
groupCircles.push({
group: groupName,
x: circle.x,
y: circle.y,
r: circle.r
});
});
示例9: swap
let _unmatch = (orbs: Orb[][], row: number, col: number, match: number[][], skipToRandom: boolean = false) => {
let thisOrb: Orb = orbs[row][col];
let swapped = false;
let directions = _.shuffle(['up', 'down', 'left', 'right']);
for (let i = 0; i < 4; i++) {
// abandons the process and jumps to swapping a random orb
if (skipToRandom) { break };
if (directions[i] === 'up' && !_.isUndefined(orbs[row - 1]) && orbs[row - 1][col] !== thisOrb) {
return swap(orbs, [[row, col], [row - 1, col]]);
} else if (directions[i] === 'down' && !_.isUndefined(orbs[row + 1]) && orbs[row + 1][col] !== thisOrb) {
return swap(orbs, [[row, col], [row + 1, col]]);
} else if (directions[i] === 'left' && !_.isUndefined(orbs[row][col - 1]) && orbs[row][col - 1] !== thisOrb) {
return swap(orbs, [[row, col], [row, col - 1]]);
} else if (directions[i] === 'right' && !_.isUndefined(orbs[row][col + 1]) && orbs[row][col + 1] !== thisOrb) {
return swap(orbs, [[row, col], [row, col + 1]]);
}
}
while (!swapped) {
let [randomRow, randomCol] = [_.random(orbs.length - 1), _.random(orbs[0].length - 1)];
if (!_.includes(match, [randomRow, randomCol]) && orbs[randomRow][randomCol] !== thisOrb) {
return swap(orbs, [[row, col], [randomRow, randomCol]]);
}
}
};