I'm trying to solve a problem with a Node API I'm working on and I got stuck at something that should be easy but I just can't figure it out. Let's say I have an array like this:
[1, 2, 1, ....]
This array can be arbitrarily long. I need to use the values in the array as keys for an object, so for the example above, I need to be able to do something like anotherObject[1][2][1] = 'hello world'
no matter how long the array is.
I've already figured out how to get the value of the object using a while loop or a recursive function but I can't figure out how to set the value like that.
(Just in case anyone figures out a way to avoid this problem all together and do what I'm trying to do differently, I'm gonna briefly sum up what I'm working on.
Imagine a social network like Twitter where you can write a post as a reply to another post. Then someone can reply to your post and so on so there can be a huge stack of posts each replying to the one that came before it. But there can also be a bunch of replies that are on the same level - all replying to the same post but not to each other. The way I store this in the database is pretty simple: if a post is a reply, it has a property that refers to the ID of the post it's replying to. If you can figure out a better way to store it, I'd love to hear it.
Now here's the issue. How do you display all the replies to a certain post and also all the replies to those replies and all the replies to the replies to those replies and so on? I've come up with a pseudo-algorithm that creates something resembling a DOM made up of comments with children and siblings and so on. I just need a way to navigate around it and modify the it. So logically, I need a way to keep track of what is what and a way to modify the individual elements. So I have the array keeping track of what the algorithm is processing at the moment and then the object that keeps track of which posts have been discovered and which ones have been processed already. If there's a better way to solve this issue, I'd love to hear it)