本文整理汇总了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,
}
}
示例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;
}
示例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);
};
示例4: equals
const isSpare = rolls => equals(10, sum(take(2, rolls)));
示例5: sum
export const score = (rolls: any = []) => {
return sum(rolls) + bonus(rolls)
};
示例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)));
}