Hey, and first of all thanks for putting effort on your post. I hope it doesn't get lost in the flood of low quality ones...
Regarding your article I just want to point out that the first two examples, despite being doable with a .reduce(), in my opinion they're way complex. We can achieve the same by doing something like:
// Pretend these are complex objectsconstposts=[{tags:["javascript","discuss"]},{tags:["javascript","react","vue-is-better"]},{tags:["discuss"]},{tags:["javascript"]},];// const allTags = posts.map(post => post.tags).flat();constallTags=posts.map(({tags})=>tags).flat();constallUniqueTags=newSet(allTags);console.log(allUniqueTags);// Set(4) { 'javascript', 'discuss', 'react', 'vue-is-better' }
Hey, and first of all thanks for putting effort on your post. I hope it doesn't get lost in the flood of low quality ones...
Regarding your article I just want to point out that the first two examples, despite being doable with a
.reduce()
, in my opinion they're way complex. We can achieve the same by doing something like:Regarding the
pipe
, that is the perfect use case for thereduce()
!Nice job explaining it.
I just wanted to bring more viable options to achieve the same outcome, not to undermine your examples.
Thanks once again!
Thanks for the kind words.
About those examples I made in the post, interestingly enough they could also be done using
Array.flatMap
.