cheatsheet/elm.js
function append(a,b)
{
	if (a.table.length === 0)
	{
		return b;
	}
	if (b.table.length === 0)
	{
		return a;
	}

	var c = append_(a, b);

	// Check if both nodes can be crunshed together.
	if (c[0].table.length + c[1].table.length <= M)
	{
		if (c[0].table.length === 0)
		{
			return c[1];
		}
		if (c[1].table.length === 0)
		{
			return c[0];
		}

		// Adjust .table and .lengths
		c[0].table = c[0].table.concat(c[1].table);
		if (c[0].height > 0)
		{
			var len = length(c[0]);
			for (var i = 0; i < c[1].lengths.length; i++)
			{
				c[1].lengths[i] += len;
			}
			c[0].lengths = c[0].lengths.concat(c[1].lengths);
		}

		return c[0];
	}

	if (c[0].height > 0)
	{
		var toRemove = calcToRemove(a, b);
		if (toRemove > E)
		{
			c = shuffle(c[0], c[1], toRemove);
		}
	}

	return siblise(c[0], c[1]);
}
function append(a,b)
{
	if (a.table.length === 0)
	{
		return b;
	}
	if (b.table.length === 0)
	{
		return a;
	}

	var c = append_(a, b);

	// Check if both nodes can be crunshed together.
	if (c[0].table.length + c[1].table.length <= M)
	{
		if (c[0].table.length === 0)
		{
			return c[1];
		}
		if (c[1].table.length === 0)
		{
			return c[0];
		}

		// Adjust .table and .lengths
		c[0].table = c[0].table.concat(c[1].table);
		if (c[0].height > 0)
		{
			var len = length(c[0]);
			for (var i = 0; i < c[1].lengths.length; i++)
			{
				c[1].lengths[i] += len;
			}
			c[0].lengths = c[0].lengths.concat(c[1].lengths);
		}

		return c[0];
	}

	if (c[0].height > 0)
	{
		var toRemove = calcToRemove(a, b);
		if (toRemove > E)
		{
			c = shuffle(c[0], c[1], toRemove);
		}
	}

	return siblise(c[0], c[1]);
}
function append ( a , b ) { if ( a . table . length === 0 ) { return b ; } if ( b . table . length === 0 ) { return a ; } var c = append_ ( a , b ) ; // Check if both nodes can be crunshed together. if ( c [ 0 ] . table . length + c [ 1 ] . table . length <= M ) { if ( c [ 0 ] . table . length === 0 ) { return c [ 1 ] ; } if ( c [ 1 ] . table . length === 0 ) { return c [ 0 ] ; } // Adjust .table and .lengths c [ 0 ] . table = c [ 0 ] . table . concat ( c [ 1 ] . table ) ; if ( c [ 0 ] . height > 0 ) { var len = length ( c [ 0 ] ) ; for ( var i = 0 ; i < c [ 1 ] . lengths . length ; i ++ ) { c [ 1 ] . lengths [ i ] += len ; } c [ 0 ] . lengths = c [ 0 ] . lengths . concat ( c [ 1 ] . lengths ) ; } return c [ 0 ] ; } if ( c [ 0 ] . height > 0 ) { var toRemove = calcToRemove ( a , b ) ; if ( toRemove > E ) { c = shuffle ( c [ 0 ] , c [ 1 ] , toRemove ) ; } } return siblise ( c [ 0 ] , c [ 1 ] ) ; }
Appends two trees.
Appends two trees .