Skip to content

Commit

Permalink
fix: sorting function
Browse files Browse the repository at this point in the history
  • Loading branch information
Rishabh-malhotraa committed Sep 13, 2022
1 parent b115689 commit d3548a7
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions api/src/utils/sortExperiences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ export const sortExperiences = (experiences: ExperienceType[]) =>
experiences.sort(experienceComparator);

const experienceComparator = (a: ExperienceType, b: ExperienceType) => {
if (a.end_year.trim().toLowerCase() === 'present') return 1;
if (b.end_year.trim().toLowerCase() === 'present') return -1;
if (a.end_year.trim().toLowerCase() === 'present') return -1;
if (b.end_year.trim().toLowerCase() === 'present') return 1;
try {
return parseInt(b.end_year.trim(), 10) - parseInt(a.end_year.trim(), 10);
return (
-1 * (parseInt(a.end_year.trim(), 10) - parseInt(b.end_year.trim(), 10))
);
} catch (e) {
return 0;
}
Expand Down

0 comments on commit d3548a7

Please sign in to comment.