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


TypeScript ramda.sum函数代码示例

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


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

示例1: httpAgentStats

export function httpAgentStats () {
  const socketsPerOrigin = countPerOrigin(httpAgent.sockets)
  const sockets = sum(values(socketsPerOrigin))
  const pendingRequestsPerOrigin = countPerOrigin(httpAgent.requests)
  const pendingRequests = sum(values(pendingRequestsPerOrigin))

  return {
    pendingRequests,
    pendingRequestsPerOrigin,
    sockets,
    socketsPerOrigin,
  }
}
开发者ID:vtex,项目名称:apps-client-node,代码行数:13,代码来源:request.ts

示例2: getSimilarity

function getSimilarity(answerMap: AnswerMap, weights: WeightMap, candidate: Candidate): number {
  const myQuestionIds = getNotSkippedQuestionIDs(answerMap);
  const candidateQuestionIds = getNotSkippedQuestionIDs(candidate.answers);
  const commonQuestionIDs = R.intersection(myQuestionIds, candidateQuestionIds);
  const weight = (id: string) => weights[id] || 1;
  const maxDeltaSum = R.sum(commonQuestionIDs.map(weight)) * 2;
  const deltas = commonQuestionIDs.map(id => {
    const myValue = answerToNumber(answerMap[id]);
    const candidateValue = answerToNumber(candidate.answers[id]);
    return Math.abs(myValue - candidateValue) * weight(id);
  });
  return (1 - (R.sum(deltas) / maxDeltaSum)) || 0;
}
开发者ID:shybyte,项目名称:wahlomat,代码行数:13,代码来源:model.ts

示例3: MockAssetResolver

const runTests = <S, F>(
  assert: (
    fixture: ExerciseFixture<S, F>,
    /* tslint:disable-next-line:no-any */
    exercise: AbstractExercise<any, S, F>
  ) => void
) => {
  const resolver = new MockAssetResolver();
  const factory = new EntityFactory(resolver);

  const cases = values(
    mapObjIndexed(
      (
        E: {
          fixtures: Array<ExerciseFixture<S, F>>;
          /* tslint:disable-next-line:no-any */
          new (p: any): AbstractExercise<any, S, F>;
        },
        type
      ) => () => {
        forEach(fixture => {
          try {
            const exercise = factory.createExercise(
              type as ExerciseTypes,
              fixture.props
            );

            // Catch test failures so that we can pass a custom message
            assert(fixture, exercise);
          } catch (e) {
            throw new Error(`${type} › ${fixture.name}:\n${e.message}`);
          }
        }, E.fixtures);
      },
      Exercises
    )
  );

  // Execute the test runners
  forEach(runTestCases => runTestCases(), cases);

  // Check that each test case was run
  const numberOfAssertions = sum(
    values(
      map<
        { [type: string]: { fixtures: Array<ExerciseFixture<S, F>> } },
        { [type: string]: number }
      >(
        (E: { fixtures: Array<ExerciseFixture<S, F>> }) => E.fixtures.length,
        Exercises
      )
    )
  );
  expect.assertions(numberOfAssertions);
};
开发者ID:serlo-org,项目名称:serlo-abc,代码行数:55,代码来源:exercises.ts

示例4: equals

const isSpare = rolls => equals(10, sum(take(2, rolls)));
开发者ID:sprengerjo,项目名称:katas_js,代码行数:1,代码来源:bowling_score_calculator.ts

示例5: sum

export const score = (rolls: any = []) => {
  return sum(rolls) + bonus(rolls)
};
开发者ID:sprengerjo,项目名称:katas_js,代码行数:3,代码来源:bowling_score_calculator.ts

示例6: solve

function solve(maxValue: number): number {
    return R.sum(R.map((n: number) => (n % 5 == 0 || n % 3 == 0) ? n : 0,
        R.range(1, maxValue)));
}
开发者ID:kellyi,项目名称:katas,代码行数:4,代码来源:ts_euler1.ts


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