Skip to content

Commit 25131f0

Browse files
Avoid sort failure due to NaN comparison
1 parent 0fd4b10 commit 25131f0

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

site/static/compare.html

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -653,8 +653,23 @@ <h2>Comparing <span id="stat-header">{{stat}}</span> between <span id="before">{
653653
b: format(b),
654654
percent: 100 * (b - a) / a
655655
};
656-
})
657-
.sort((a, b) => Math.abs(b.percent) - Math.abs(a.percent));
656+
}).sort((a, b) => {
657+
let bp = Math.abs(b.percent);
658+
if (Number.isNaN(bp)) {
659+
bp = 0;
660+
}
661+
let ap = Math.abs(a.percent);
662+
if (Number.isNaN(ap)) {
663+
ap = 0;
664+
}
665+
if (bp < ap) {
666+
return -1;
667+
} else if (bp > ap) {
668+
return 1;
669+
} else {
670+
return a.name.localeCompare(b.name);
671+
}
672+
});
658673
},
659674
before() {
660675
if (!this.data) {

0 commit comments

Comments
 (0)