cheatsheet/elm.js
function fromListPush(toPush, nodes)
{
	var h = toPush.height;

	// Maybe the node on this height does not exist.
	if (nodes.length === h)
	{
		var node = {
			ctor: '_Array',
			height: h + 1,
			table: [],
			lengths: []
		};
		nodes.push(node);
	}

	nodes[h].table.push(toPush);
	var len = length(toPush);
	if (nodes[h].lengths.length > 0)
	{
		len += nodes[h].lengths[nodes[h].lengths.length - 1];
	}
	nodes[h].lengths.push(len);

	if (nodes[h].table.length === M)
	{
		fromListPush(nodes[h], nodes);
		nodes[h] = {
			ctor: '_Array',
			height: h + 1,
			table: [],
			lengths: []
		};
	}
}
function fromListPush(toPush, nodes)
{
	var h = toPush.height;

	// Maybe the node on this height does not exist.
	if (nodes.length === h)
	{
		var node = {
			ctor: '_Array',
			height: h + 1,
			table: [],
			lengths: []
		};
		nodes.push(node);
	}

	nodes[h].table.push(toPush);
	var len = length(toPush);
	if (nodes[h].lengths.length > 0)
	{
		len += nodes[h].lengths[nodes[h].lengths.length - 1];
	}
	nodes[h].lengths.push(len);

	if (nodes[h].table.length === M)
	{
		fromListPush(nodes[h], nodes);
		nodes[h] = {
			ctor: '_Array',
			height: h + 1,
			table: [],
			lengths: []
		};
	}
}
function fromListPush ( toPush , nodes ) { var h = toPush . height ; // Maybe the node on this height does not exist. if ( nodes . length === h ) { var node = { ctor : '_Array' , height : h + 1 , table : [ ] , lengths : [ ] } ; nodes . push ( node ) ; } nodes [ h ] . table . push ( toPush ) ; var len = length ( toPush ) ; if ( nodes [ h ] . lengths . length > 0 ) { len += nodes [ h ] . lengths [ nodes [ h ] . lengths . length - 1 ] ; } nodes [ h ] . lengths . push ( len ) ; if ( nodes [ h ] . table . length === M ) { fromListPush ( nodes [ h ] , nodes ) ; nodes [ h ] = { ctor : '_Array' , height : h + 1 , table : [ ] , lengths : [ ] } ; } }
Push a node into a higher node as a child.
Push a node into a higher node as a child .