Nothing here yet.
Nothing here yet.
No blogs yet.
Combing a source code editor (ace.js) and visualisations created with d3.js to encode the various aspects within a source code document. Prototype 1 - https://js-scope-vis.aerobatic.io/ Prototype 2 - https://mute-pocket.aerobatic.io/ Prototype 3 - https://possible-thread.aerobatic.io/
The function nest() takes two parameters 1) el and 2) parent . The first time nest is called we pass a (first element of the array) and root to the function. Nest() creates a new object called node . Node then gets added to the parent parameter. Parent corresponds to root the first time the function is called. Then node is returned. A reference of node is actually returned and not a copy (THIS IS IMPORTANT). Therefore, when nest() gets called a second time the parent parameter is actually a reference to the first node object that was created in the previously called nest() function.
let list = [ 'a' , 'b' , 'c' ] let root = {} let parent = null ; for (let el of list ) { if ( parent === null ) parent = nest(el, root) else { parent = nest(el, parent ); } } function nest (el, parent) { let node = {} parent [el] = node; return node; } console.log(root); Output { a : { b: { c: {} } } }