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


TypeScript ramda.times函数代码示例

本文整理汇总了TypeScript中ramda.times函数的典型用法代码示例。如果您正苦于以下问题:TypeScript times函数的具体用法?TypeScript times怎么用?TypeScript times使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了times函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: it

    it('should assert many', () => {
        const n = 50000;
        const unsorted = R.times(() => Math.floor(Math.random() * (n - 1 + 1) + 1), n);

        const sorted = sort(unsorted);
        let ramdaSorted = R.sort(R.subtract, unsorted);

        expect(sorted).toEqual(ramdaSorted);
    });
开发者ID:sprengerjo,项目名称:katas_js,代码行数:9,代码来源:test_sort.spec.ts

示例2: filter

 ...map(word => {
   const wordObj = this.createWord(word);
   const wordLetters = (wordObj ? wordObj.toString() : word).split('');
   const numberOfOptions: number = 3;
   const numberMissing: number =
     this.props.difficulty < 0.2
       ? 1
       : this.props.difficulty < 0.4
       ? 2
       : this.props.difficulty < 0.6
       ? 3
       : this.props.difficulty < 0.8
       ? 4
       : wordLetters.length;
   const knownLettersInWord = filter(
     i => indexOf(wordLetters[i].toLowerCase(), this.letters) !== -1,
     times(identity, wordLetters.length)
   );
   const missing = sample(knownLettersInWord, numberMissing);
   const options = map(missingLetterIndex => {
     const opt = sample(
       [
         ...sample(
           without(
             [wordLetters[missingLetterIndex].toLowerCase()],
             this.letters
           ),
           numberOfOptions - 1
         ),
         wordLetters[missingLetterIndex]
       ],
       numberOfOptions
     );
     return wordLetters[missingLetterIndex] ===
       wordLetters[missingLetterIndex].toLowerCase()
       ? map(s => s.toLowerCase(), opt)
       : map(capitalizeFirstLetter, opt);
   }, missing);
   return this.createExercise(ExerciseTypes.MissingText, {
     type: 'MissingText',
     word,
     text: wordLetters,
     missing,
     options
   });
 }, words)
开发者ID:serlo-org,项目名称:serlo-abc,代码行数:46,代码来源:missing-letter.ts

示例3: generateExercises

  protected generateExercises() {
    const numberOfLetters = this.props.difficulty < 0.2 ? 3 : 5;
    const numberOfRotated = this.props.difficulty < 0.5 ? 1 : 2;
    const letters: string[] = sample(this.letters, numberOfLetters);
    const rotated: number[] = sample(
      times(identity, numberOfLetters),
      numberOfRotated
    );
    const angles: string[] = map(() => {
      const sign = [-1, 1][getRandomInt(0, 1)];
      const angle = getRandomInt(3, 15) * 10 * sign;
      return `${angle}deg`;
    }, rotated);

    const version = sample(['a', 'b'], 1);
    const text: string =
      numberOfRotated > 1
        ? 'Welche Buchstaben sind gedreht?'
        : 'Welcher Buchstabe ist gedreht';
    const sound: string =
      numberOfRotated > 1
        ? `exercises_welche_buchstaben_sind_gedreht_${version}`
        : `exercises_welcher_buchstabe_ist_gedreht_${version}`;

    return [
      this.createExercise(ExerciseTypes.InfoScreenWithSounds, {
        type: 'ExplanationText',
        text,
        sound
      }),
      this.createExercise(ExerciseTypes.InfoScreen, {
        type: 'TutorialVideo',
        video: 'explanation_letter_rotated'
      }),
      this.createExercise(ExerciseTypes.LetterRotated, {
        type: 'LetterRotated',
        letters,
        rotated,
        angles,
        difficulty: this.props.difficulty
      })
    ];
  }
开发者ID:serlo-org,项目名称:serlo-abc,代码行数:43,代码来源:letter-rotated.ts

示例4: map

        map(word => {
          const wordObj = this.createWord(word);
          if (!wordObj) {
            return undefined;
          }
          const syllablesRawString = wordObj.getRawSingular();
          if (!syllablesRawString || syllablesRawString.indexOf('|') === -1) {
            return undefined;
          }
          const syllables = syllablesRawString.replace(/['-]/g, '').split('|');

          const missingSyllableIndices = sample(
            times(identity, syllables.length),
            1
          );
          try {
            const options = map(missingSyllableIndex => {
              const syllableOptions = this.createOptionsForSyllable(
                syllables[missingSyllableIndex]
              );
              if (!syllableOptions) {
                throw new Error(
                  `ConnectSyllables: Options empty at word ${syllablesRawString}, syllable ${missingSyllableIndex}`
                );
              }
              return syllableOptions;
            }, missingSyllableIndices);

            return this.createExercise(ExerciseTypes.MissingText, {
              type: 'MissingText',
              word,
              text: syllables,
              missing: missingSyllableIndices,
              options
            });
          } catch (err) {
            Sentry.captureException(err);
            return undefined;
          }
        }, words)
开发者ID:serlo-org,项目名称:serlo-abc,代码行数:40,代码来源:connect-syllables.ts

示例5: it

 it('perfect games score is 300', () => {
   const rolls = times(always(10), 12);
   expect(score(rolls)).toEqual(300)
 });
开发者ID:sprengerjo,项目名称:katas_js,代码行数:4,代码来源:bowling_score_calculator.spec.ts

示例6: generateBookmarkInfo

export const generateBookmarkTree = () => ({
  children: R.times(() => generateBookmarkInfo(), 20),
  parent: generateBookmarkInfo(CST.BOOKMARK_TYPES.FOLDER)
})
开发者ID:foray1010,项目名称:Popup-my-Bookmarks,代码行数:4,代码来源:bookmarkTrees.ts


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