is there any way to reverse the object in js?
const initObject = {
value: 5,
next: {
value: 10,
next: {
value: 15
next: null
}
},
}
//expected result
const newObject = {
value: 15,
next: {
value: 10,
next: {
value: 5,
next: null
}
}
}
need to a function, but struggling hard.
I tried to find the object depth-first and then make a founded amount of iterations for … in … inside the object but don’t know how to rewrite the new one