當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。