• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript lodash.sampleSize函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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'
  })
}
开发者ID:czb128abc,项目名称:gouqi,代码行数:58,代码来源:recommend.ts


示例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;
    }, [])
开发者ID:radotzki,项目名称:bullshit-server,代码行数:15,代码来源:start.ts


示例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)
     )
 })
开发者ID:kengorab,项目名称:njt-api,代码行数:7,代码来源:station-manager.test.ts


示例4: getKillerLoadout

 async getKillerLoadout(): Promise<ILoadout> {
   return {
     item: await this.getRandomKiller(),
     offering: null,
     perks: _.sampleSize( (await this.fetch()).killers.perks, 4 )
   };
 }
开发者ID:solarflare045,项目名称:ultimate-bravery,代码行数:7,代码来源:randomizer.service.ts


示例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 )
   });
 }
开发者ID:solarflare045,项目名称:ultimate-bravery,代码行数:7,代码来源:randomizer.service.ts


示例6: getSurvivorLoadout

 async getSurvivorLoadout(): Promise<ILoadout> {
   return {
     item: await this.getRandomItem(),
     offering: null,
     perks: _.sampleSize( (await this.fetch()).survivors.perks, 4 )
   };
 }
开发者ID:solarflare045,项目名称:ultimate-bravery,代码行数:7,代码来源:randomizer.service.ts


示例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 )
   });
 }
开发者ID:solarflare045,项目名称:ultimate-bravery,代码行数:7,代码来源:randomizer.service.ts


示例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)
      })
开发者ID:kengorab,项目名称:njt-api,代码行数:11,代码来源:api.test.ts


示例9: getFakeAnswers

export function getFakeAnswers(count: number) {
    return _.sampleSize(fakeAnswersArray, count);
}
开发者ID:radotzki,项目名称:bullshit-server,代码行数:3,代码来源:staticFakeAnswers.ts



注:本文中的lodash.sampleSize函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript lodash.set函数代码示例发布时间:2022-05-25
下一篇:
TypeScript lodash.sample函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap