Note the code below shows the array in the console, not in the snippet output
var nodes = ["maria", "mary", "marks", "michael"];
function insert_word(split_nodes) {
var rest = [];
for (var i = 0; i < split_nodes.length; i++) {
//console.log(current);
var word = split_nodes[i];
var letters = word.split("");
var current = rest;
console.log(current);
for (var j = 0; j < letters.length; j++) {
var character = letters[j];
var position = current[character];
if (position == null) {
current = current[character] = j == letters.length - 1 ? 0 : {};
} else {
current = current[character];
}
}
}
}
insert_word(nodes);
Above outputs this
M :{a : {r :{i :{a :0},
k :0,
y :
},
},
i :{c :{h :{a :{e :{l :0}}}}}}}
but I want to output this :
M :{ar:{ia:0,
k :0,
y :0
},
ichael :0
}
can anyone help me to find out this output from my code? how could i make suffeix from this code?