From c5049c28c45867489da286657b4419aa0b23ad45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kratochv=C3=ADl?= <xkrato10@fi.muni.cz> Date: Thu, 23 Jun 2022 23:37:29 +0200 Subject: [PATCH] fix: BrowseDirectors - birthdate sorting when undefined, added comments --- frontend/src/components/BrowseDirectors.tsx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/frontend/src/components/BrowseDirectors.tsx b/frontend/src/components/BrowseDirectors.tsx index 51b8488..d049020 100644 --- a/frontend/src/components/BrowseDirectors.tsx +++ b/frontend/src/components/BrowseDirectors.tsx @@ -19,7 +19,6 @@ const exampleDirectors: DirectorIO[] = [{ id: "890", name: "Karel", surname: "Vomacka", - birthdate: "1.2.1987", }, { id: "666", @@ -58,15 +57,18 @@ export const BrowseDirectors = () => { const second = b?.birthdate?.split('.').reverse(); if (first === undefined && second === undefined) { return 0; } - if (first === undefined) { return 1;} - if (second === undefined) { return -1;} + if (first === undefined) { return -1;} + if (second === undefined) { return 1;} + // year if (first[0] > second[0]) {return 1;} if (first[0] < second[0]) {return -1;} - + + // month if (first[1] > second[1]) {return 1;} if (first[1] < second[1]) {return -1;} - + + // day if (first[2] > second[2]) {return 1;} if (first[2] < second[2]) {return -1;} return 0; -- GitLab