本文整理汇总了TypeScript中lodash.sampleSize函数的典型用法代码示例。如果您正苦于以下问题:TypeScript sampleSize函数的具体用法?TypeScript sampleSize怎么用?TypeScript sampleSize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sampleSize函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: recommendSaga
export function* recommendSaga () {
const isLogin = yield call(api.getUserId)
const promises = [
api.topPlayList('30'),
api.newAlbums('30'),
api.topArtists('30')
]
if (isLogin) {
promises.push(api.dailyRecommend('30'))
}
yield put({
type: 'home/recommend/start'
})
try {
const [
playlists,
albums,
artists,
songs
] = yield call(Promise.all, promises)
if (playlists.code === 200) {
yield put({
type: 'playlists/sync/save',
payload: changeCoverImgUrl(playlists.playlists),
meta: {
more: true,
offset: 0
}
})
}
if (albums.code === 200 && artists.code === 200) {
yield put({
type: 'home/recommend/save',
payload: {
albums: sampleSize(albums.albums, 6),
artists: sampleSize(artists.artists, 6)
}
})
}
if (songs && songs.code === 200) {
yield put({
type: 'personal/daily/save',
payload: songs.recommend.slice(0, 6)
})
}
} catch (error) {
yield put(toastAction('error', '网络出现错误..'))
}
yield put({
type: 'home/recommend/end'
})
}
示例2: function
return _.reduce(categories, function(total, category) {
const categoryQuestionsIds = _.map(category.questions, 'id');
const unplayedQuestionsIdsInCategory = _.difference(categoryQuestionsIds, playedQuestionsIds);
let replayedQuestionsIdsInCategory = [];
if (unplayedQuestionsIdsInCategory.length < category.questionsCount) {
//we don't have enough unplayed questions, we have to reuse played ones
const replayedQuestionsCount = category.questionsCount - unplayedQuestionsIdsInCategory.length;
replayedQuestionsIdsInCategory = _.sampleSize(_.intersection(categoryQuestionsIds, playedQuestionsIds), replayedQuestionsCount);
}
const selectedCategoryQuestionsIds = _.sampleSize(replayedQuestionsIdsInCategory.concat(unplayedQuestionsIdsInCategory), category.questionsCount);
const selectedQuestionsInCategory = _.filter(category.questions, question => _.includes(selectedCategoryQuestionsIds, question.id));
total = total.concat(selectedQuestionsInCategory);
return total;
}, [])
示例3: it
it('should return undefined if station is invalid', () => {
_.sampleSize(Object.keys(stationInfo), 10)
.map(station => station + 'random-crap')
.forEach(invalidStation =>
expect(StationManager.getStation(invalidStation)).toBe(undefined)
)
})
示例4: getKillerLoadout
async getKillerLoadout(): Promise<ILoadout> {
return {
item: await this.getRandomKiller(),
offering: null,
perks: _.sampleSize( (await this.fetch()).killers.perks, 4 )
};
}
示例5: 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 )
});
}
示例6: getSurvivorLoadout
async getSurvivorLoadout(): Promise<ILoadout> {
return {
item: await this.getRandomItem(),
offering: null,
perks: _.sampleSize( (await this.fetch()).survivors.perks, 4 )
};
}
示例7: getRandomItem
async getRandomItem(): Promise<TItem> {
const survivors = (await this.fetch()).survivors;
const item = _.chain(survivors.items).sample().sample().value();
return _.extend({}, item, {
addons: _.sampleSize( survivors.addons[ item.type ], 2 )
});
}
示例8: it
it('should call TripManager for trip options, passing "to" and "from" stations, and date', async () => {
const [fromStationName, toStationName] = _.sampleSize(Object.keys(stationInfo), 2)
await API.Trips.getTripOptions(fromStationName, toStationName, moment().toDate())
expect(TripManager.getTripOptionsFromNJTPage).toHaveBeenCalled()
const [fromStation, toStation, date] =
(TripManager.getTripOptionsFromNJTPage as jest.Mock<Promise<Trip[]>>).mock.calls[0]
expect(fromStation).toEqual(stationInfo[fromStationName])
expect(toStation).toEqual(stationInfo[toStationName])
expect(moment().diff(moment(date))).toBeLessThan(1000) // Verify dates are less than 1s apart (close enough)
})
示例9: getFakeAnswers
export function getFakeAnswers(count: number) {
return _.sampleSize(fakeAnswersArray, count);
}