That's a really cool fully immutable solution.
I understand it, but I would personally avoid it in JS, if not for readability by juniors then at least because I have an addiction to micro optimization.
constidsByCategory=posts=>{constcategories=newMap()// I prefer Mapfor(const{category,id}ofposts){constexisting=categories.get(category)if(!existing)categories.set(category,[id])elseexisting.push(id)}returncategories}// This is what Prettier does to itconstcategoryPosts=posts.reduce((acc,{id,category})=>({...acc,[category]:[...(acc[category]||[]),id]}),{})// Yes, this is short.constcategoryPosts=posts.reduce((acc,{id,category})=>({...acc,[category]:[...(acc[category]||[]),id]}),{})
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
That's a really cool fully immutable solution.
I understand it, but I would personally avoid it in JS, if not for readability by juniors then at least because I have an addiction to micro optimization.