本文整理汇总了TypeScript中lodash.sample函数的典型用法代码示例。如果您正苦于以下问题:TypeScript sample函数的具体用法?TypeScript sample怎么用?TypeScript sample使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sample函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: RandomUsers
static RandomUsers(count:number): User[]{
let users:User[]=[];
for(let i=0;i<count; i++){
users.push(new User(i, _.sample(FIRST_NAMES), _.sample(LAST_NAMES)));
}
return users;
}
示例2: parseInt
const addUsers = (count, knex, date) => {
count = parseInt(count)
const rows = []
for (let i = 0; i < count; i++) {
const channel = _.sample(channels)
const id = _.uniqueId()
const first_name = { key: 'first_name', value: generateName(), type: 'string' }
const last_name = { key: 'last_name', value: generateName(), type: 'string' }
const gender = { key: 'gender', value: Math.random() < vary(0.65, 0.35) ? 'male' : 'female', type: 'string' }
const locale = { key: 'locale', value: _.sample(['en_US', 'fr_CA', 'en_CA']), type: 'string' }
const timezone = { key: 'timezone', value: _.random(-6, 12, false), type: 'string' }
const user = {
user_id: id,
channel: channel,
attributes: JSON.stringify([first_name, last_name, gender, locale, timezone]),
created_at: date
}
users.push(user)
rows.push(user)
}
return knex.batchInsert('srv_channel_users', rows, 20).then(() => console.log('Added', count, 'users'))
}
示例3: times
return times(4, () => {
const device = sample (devices);
const location = sample(locations);
return {
device: device,
location: location,
name : sample(['Cloud', 'Lamp', 'Bridge']),
pin: sample(device.pins)
};
});
示例4: sample
const CONTACTS = COLORS.map((color, index) => {
const title = `${sample(['Mr.', 'Mrs.', 'Ms.', 'Unknown'])} ${color} 🔥`;
const key = sample(['name', 'profileName']) as string;
const id = `+1202555${padStart(index.toString(), 4, '0')}`;
const contact = {
color,
[key]: title,
id,
type: 'private',
};
return parent.ConversationController.dangerouslyCreateAndAdd(contact);
});
示例5: enterScored
function enterScored(state: State) {
const goalText = sample(goalWords);
return state
.setIn(['round', 'scored'], true)
.setIn(['round', 'goalText'], goalText);
}
示例6: enabler
"!typegame": enabler((command: Tennu.Command) => {
var cache = typegameCache[command.channel] = typegameCache[command.channel] || { running: false };
if (typegameCache[command.channel].running) {
return util.format("A game is still running! Name %s Pokémon with the type %s!", cache.cnt, cache.types.join("/"));
} else {
(runningCache[command.channel] = runningCache[command.channel] || []).push("typegame")
var {type, cnt} = _.sample(Data.type_count_array);
console.log(cnt);
cache = typegameCache[command.channel] = {
running: true,
type: type,
cnt: _.random(1, _.min([5, cnt])),
max: cnt,
userCount: {},
guessed: {},
types: []
};
for (var i = 0; type; type >>= 1, ++i) {
if (type&1)
cache.types.push(Data.type_list[i]);
}
return util.format("Name %s Pokémon with the type %s!",
cache.cnt, cache.types.join("/")
);
}
}),
示例7: getRandomKiller
async getRandomKiller(): Promise<TKiller> {
const killers = (await this.fetch()).killers;
const killer = _.sample( killers.abilities );
return _.extend({}, killer, {
addons: _.sampleSize( killers.addons[ killer.name.replace(/The\s/, '') ], 2 )
});
}
示例8: constructor
constructor(private readonly log: Logger, private readonly options: BasePathProxyServerOptions) {
const ONE_GIGABYTE = 1024 * 1024 * 1024;
options.httpConfig.maxPayload = new ByteSizeValue(ONE_GIGABYTE);
if (!options.httpConfig.basePath) {
options.httpConfig.basePath = `/${sample(alphabet, 3).join('')}`;
}
}
示例9:
.then(pool => {
if (pool.length === 0) return null;
if (this.preferredTaskType) {
const task = _.find(pool, t => t.templateType === this.preferredTaskType);
if (task) return task;
}
return _.sample(pool);
});
示例10: updateNextDirection
updateNextDirection() {
let allDirections = [Phaser.LEFT, Phaser.RIGHT, Phaser.UP, Phaser.DOWN];
let possibleDirections = _.filter(allDirections, (direction) => {
return direction !== this.currentDirection && direction !== this.opposites[this.currentDirection];
});
this.nextDirection = _.sample(possibleDirections);
return this.nextDirection;
}