@@ -2,14 +2,17 @@ import { EventId, Person } from '@wca/helpers';
22import { findPR } from './activities' ;
33import { isRankedBySingle } from './events' ;
44
5- export const byWorldRanking = ( eventId : EventId ) : ( ( a : Person , b : Person ) => number ) => {
5+ export const byWorldRanking = (
6+ eventId : EventId ,
7+ resultType : 'average' | 'single' = 'average' ,
8+ ) : ( ( a : Person , b : Person ) => number ) => {
69 // const byEventRanking = byRanking(eventId);
710 const findEventPR = findPR ( eventId ) ;
811
912 return ( a , b ) => {
1013 if ( ! isRankedBySingle ( eventId ) ) {
11- const aPRAverage = findEventPR ( a . personalBests || [ ] , 'average' ) ;
12- const bPRAverage = findEventPR ( b . personalBests || [ ] , 'average' ) ;
14+ const aPRAverage = findEventPR ( a . personalBests || [ ] , resultType ) ;
15+ const bPRAverage = findEventPR ( b . personalBests || [ ] , resultType ) ;
1316
1417 if ( aPRAverage && bPRAverage ) {
1518 const diff = aPRAverage . worldRanking - bPRAverage . worldRanking ;
@@ -23,20 +26,24 @@ export const byWorldRanking = (eventId: EventId): ((a: Person, b: Person) => num
2326 }
2427 }
2528
26- const aPRSingle = findEventPR ( a . personalBests || [ ] , 'single' ) ;
27- const bPRSingle = findEventPR ( b . personalBests || [ ] , 'single' ) ;
29+ if ( resultType === 'average' ) {
30+ const aPRSingle = findEventPR ( a . personalBests || [ ] , 'single' ) ;
31+ const bPRSingle = findEventPR ( b . personalBests || [ ] , 'single' ) ;
2832
29- if ( aPRSingle && bPRSingle ) {
30- const diff = aPRSingle . worldRanking - bPRSingle . worldRanking ;
31- if ( diff !== 0 ) {
32- return diff ;
33+ if ( aPRSingle && bPRSingle ) {
34+ const diff = aPRSingle . worldRanking - bPRSingle . worldRanking ;
35+ if ( diff !== 0 ) {
36+ return diff ;
37+ }
38+ } else if ( aPRSingle && ! bPRSingle ) {
39+ return - 1 ;
40+ } else if ( ! aPRSingle && bPRSingle ) {
41+ return 1 ;
3342 }
34- } else if ( aPRSingle && ! bPRSingle ) {
35- return - 1 ;
36- } else if ( ! aPRSingle && bPRSingle ) {
37- return 1 ;
43+
44+ return a . name . localeCompare ( b . name ) ;
3845 }
3946
40- return a . name . localeCompare ( b . name ) ;
47+ return 0 ;
4148 } ;
4249} ;
0 commit comments