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