jweinst1
5/15/2016 - 1:35 AM

mach2node.js

//tree machine fiddle

//node for powering the tree machine
//operates as doubly linked list
var MachineNode = (function(){
	function MachineNode(value){
		this.value = value || null;
		this.links = [];
		this.Parent = false;
	}
	//sets parent node
	MachineNode.prototype.setParent = function(obj){
		this.Parent = obj;
	};
	//appends new mach node
	MachineNode.prototype.append = function(value){
		var child = new MachineNode(value);
		child.setParent(this);
		this.links.push(child);
	};
	//removes some child node from the links arry
	MachineNode.prototype.remove = function(index){
		this.links.splice(index, 1);
	};
	
	//gets value of child node, only if index exists
	MachineNode.prototype.getLinkValue = function(index){
		if(index in this.links) return this.links[index].value;
	};
	return MachineNode;
})();