1

You have an array of objects with a startIndex and endIndex representing their position in a string & you want to end up with a nested structure to represent their relation in the string (i.e., A is from 1 to 10, B from 3 to 5, C from 4 to 5, D from 7 to 9). How would you do it?

Input array looks like: https://gist.github.com/AmyShackles...

Desired output looks like: https://gist.github.com/AmyShackles...

(Though what I really have to start with is an object whose keys are the start index and whose values are values of each element in the above input array, so if you can think of a way to morph it without needing to turn it into an array first that’d also be cool)

Figured I’ve been stuck on this part of my side project for long enough that I really should just make a desperate cry for help. ❤️

Comments
Add Comment