From 2c6f685b705ceefd682bea8e8c9f3f6e94a6e918 Mon Sep 17 00:00:00 2001 From: Mhykol Date: Wed, 8 May 2024 05:33:34 -0400 Subject: Added sortByDate function to handle map entries in blog.js --- source/blog.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/source/blog.js b/source/blog.js index 8e0922f..a45267e 100644 --- a/source/blog.js +++ b/source/blog.js @@ -57,10 +57,21 @@ class Blog { }) } }) - res(this.blog) + res(this.#OrderByDate(this.blog)) }) }) } + + #OrderByDate(x) { + const entries =[] + x.forEach((value, key) => {entries.push([key, value])}) + entries.sort((a, b) => { + const dateA = b[1].date + const dateB = a[1].date + return dateA - dateB + }) + return new Map(entries) + } } module.exports = () => {return new Blog()} -- cgit v1.2.3-70-g09d2