当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript lodash.sampleSize函数代码示例

本文整理汇总了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;未经允许,请勿转载。