File tree Expand file tree Collapse file tree 2 files changed +19
-18
lines changed Expand file tree Collapse file tree 2 files changed +19
-18
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ import {
1616import {
1717 generateZeroMatrix ,
1818 getRankingForSetOfDampingFactors ,
19+ makeIt100 ,
1920 toFixedNumber ,
2021} from 'src/utils/mathematical-logic' ;
2122import {
@@ -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) => {
Original file line number Diff line number Diff 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
133133export const calculateCollectionRanking = (
134134 input : number [ ] [ ] ,
You can’t perform that action at this time.
0 commit comments