ProtoSchool / protoschool.github.io

The code that runs the ProtoSchool website. Visit https://proto.school for interactive tutorials on decentralized web protocols. Explore IPFS and Filecoin through code challenges, code-free lessons, and local events.
https://proto.school
Other
166 stars 67 forks source link

Lesson Feedback%3A Blog - Lesson 7 (Traverse through all posts, starting with the most recent) #799

Open andrewzhurov opened 2 years ago

andrewzhurov commented 2 years ago

URL of the lesson that's confusing: https://proto.school/blog/07

What's confusing about this lesson? It suggests to use push mutating-op in order to assemble the result, mutations are evil, perhaps it can be suggested to use recursion?

Resulting function would be something of this sort:

const traversePosts = async (cid) => {
  // Your code goes here
  postGetResult = await ipfs.dag.get(cid)
  post = postGetResult.value

  return !post.prev ? [cid] : [cid, ... await traversePosts(post.prev)]
}