Skip to content

Commit 4953c37

Browse files
committed
Double check 100 summation
1 parent 6f411b1 commit 4953c37

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

src/flow/flow.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
import {
1717
generateZeroMatrix,
1818
getRankingForSetOfDampingFactors,
19+
makeIt100,
1920
toFixedNumber,
2021
} from 'src/utils/mathematical-logic';
2122
import {
@@ -530,7 +531,7 @@ export class FlowService {
530531
})),
531532
];
532533

533-
return ranking.sort((a, b) => a.rank - b.rank);
534+
return makeIt100(ranking.sort((a, b) => a.rank - b.rank));
534535
};
535536

536537
// getRootRanking = async (userId: number) => {

src/utils/mathematical-logic/index.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -107,28 +107,28 @@ const validate = (input: { share: number }[]) => {
107107
return false;
108108
};
109109

110-
// export function makeIt100<T extends { share: number }>(input: T[]) {
111-
// let result = [...input];
110+
export function makeIt100<T extends { share: number }>(input: T[]) {
111+
let result = [...input];
112112

113-
// let breakLimit = 0;
114-
// while (!validate(result) && breakLimit < 100) {
115-
// const sum = result.reduce((acc, curr) => (acc += curr.share), 0);
113+
let breakLimit = 0;
114+
while (!validate(result) && breakLimit < 100) {
115+
const sum = result.reduce((acc, curr) => (acc += curr.share), 0);
116116

117-
// const temp = result.map((item) => ({
118-
// ...item,
119-
// share: (item.share * 1) / sum,
120-
// }));
117+
const temp = result.map((item) => ({
118+
...item,
119+
share: (item.share * 1) / sum,
120+
}));
121121

122-
// result = temp.map((item) => ({
123-
// ...item,
124-
// share: toFixedNumber(item.share, 6),
125-
// }));
122+
result = temp.map((item) => ({
123+
...item,
124+
share: toFixedNumber(item.share, 6),
125+
}));
126126

127-
// breakLimit++;
128-
// }
127+
breakLimit++;
128+
}
129129

130-
// return result;
131-
// }
130+
return result;
131+
}
132132

133133
export const calculateCollectionRanking = (
134134
input: number[][],

0 commit comments

Comments
 (0)