Implement javascript function using tail recursion
问题 I have got a flat array representing a tree, and I want to build a nested object using tail recursion. I've got the following code to run and generate the desired output, but I am not sure if it is a proper implementation of tail recursion. Please advice :) const myArray = [ { id: 'root' }, { id: 0, parent: 'root' }, { id: 1, parent: 'root' }, { id: 2, parent: 0 }, { id: 3, parent: 1 }, { id: 4, parent: 2 }, { id: 5, parent: 1 }, { id: 6, parent: 4 }, { id: 7, parent: 0 }, { id: 8, parent: 0