Created
February 7, 2022 09:00
-
-
Save 1ay1/6eebf40f5b78155a5d55052a6a079dea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// def merge_posts(list_of_posts: List[List[Post]]) -> List[Post] | |
function merge_posts(list_of_posts) { | |
let posts = []; | |
list_of_posts.map(val => { | |
posts.concat(val); | |
}); | |
//only uniques | |
posts = posts.filter((val, index) => posts.indexOf(val) === index); | |
//sort the thing | |
posts.sort((l, r) => { | |
if(l.created_at > r.created_at) { | |
return -1; | |
} else { | |
if(l.id == r.created_at) { | |
//break the tie | |
if(l.id > r.id) return -1; | |
else return 1; | |
} | |
return 1; | |
} | |
}) | |
let response = posts.map((val, index) => { | |
return { | |
id: val.id, | |
description: val.description, | |
image: val.image, | |
created_at: cal.created_at, | |
} | |
}) | |
return response; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment