go-ethereum/src/utils/compareReleasesFn.ts
Corwin Smith 4aa8f214fb
[sorting] releases should be sorted by date, then by type (Geth, then Geth + tools) (#158)
* create constant for number of releases per os

* sort releases

* Apply suggestions from code review

* change requests

* fix build error

* cleanup

* fix: typo & prettier

* refactor sort function

* cleanup unnecessary changes

* fix: getReleaseArch case

* fix sort

* prettier

Co-authored-by: Paul Wackerow <54227730+wackerow@users.noreply.github.com>
Co-authored-by: Nicolás Quiroz <nh.quiroz@gmail.com>
2022-12-15 12:27:49 -03:00

18 lines
545 B
TypeScript

import { ReleaseData } from '../types';
export const compareReleasesFn = (a: ReleaseData, b: ReleaseData) => {
const aPublished = new Date(a.published);
const bPublished = new Date(b.published);
const sameDate = aPublished.toDateString() === bPublished.toDateString();
const sameCommit = a.commit.label === b.commit.label;
if (sameDate && !sameCommit) {
return aPublished > bPublished ? -1 : 1;
}
if (sameDate) {
return a.release.label.length - b.release.label.length;
}
return aPublished > bPublished ? -1 : 1;
};