Skip to content

Commit

Permalink
feat : sorting by creation time/date added
Browse files Browse the repository at this point in the history
  • Loading branch information
t007rushi committed Apr 7, 2022
1 parent 35832b3 commit 4c14851
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/utils/getSortedbydate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const sortbydate = (state, notes) => {
if (state.sortby === "old") {
return [...notes].sort(
(a, b) => Date.parse(a.Note.createdAt) - Date.parse(b.Note.createdAt)
);
} else if (state.sortby === "new") {
return [...notes].sort(
(a, b) => Date.parse(b.Note.createdAt) - Date.parse(a.Note.createdAt)
);
}
return notes;
};

0 comments on commit 4c14851

Please sign in to comment.