cheatsheet/elm.js
function push_(item, a)
{
	// Handle resursion stop at leaf level.
	if (a.height === 0)
	{
		if (a.table.length < M)
		{
			var newA = {
				ctor: '_Array',
				height: 0,
				table: a.table.slice()
			};
			newA.table.push(item);
			return newA;
		}
		else
		{
		  return null;
		}
	}

	// Recursively push
	var pushed = push_(item, botRight(a));

	// There was space in the bottom right tree, so the slot will
	// be updated.
	if (pushed !== null)
	{
		var newA = nodeCopy(a);
		newA.table[newA.table.length - 1] = pushed;
		newA.lengths[newA.lengths.length - 1]++;
		return newA;
	}

	// When there was no space left, check if there is space left
	// for a new slot with a tree which contains only the item
	// at the bottom.
	if (a.table.length < M)
	{
		var newSlot = create(item, a.height - 1);
		var newA = nodeCopy(a);
		newA.table.push(newSlot);
		newA.lengths.push(newA.lengths[newA.lengths.length - 1] + length(newSlot));
		return newA;
	}
	else
	{
		return null;
	}
}
function push_(item, a)
{
	// Handle resursion stop at leaf level.
	if (a.height === 0)
	{
		if (a.table.length < M)
		{
			var newA = {
				ctor: '_Array',
				height: 0,
				table: a.table.slice()
			};
			newA.table.push(item);
			return newA;
		}
		else
		{
		  return null;
		}
	}

	// Recursively push
	var pushed = push_(item, botRight(a));

	// There was space in the bottom right tree, so the slot will
	// be updated.
	if (pushed !== null)
	{
		var newA = nodeCopy(a);
		newA.table[newA.table.length - 1] = pushed;
		newA.lengths[newA.lengths.length - 1]++;
		return newA;
	}

	// When there was no space left, check if there is space left
	// for a new slot with a tree which contains only the item
	// at the bottom.
	if (a.table.length < M)
	{
		var newSlot = create(item, a.height - 1);
		var newA = nodeCopy(a);
		newA.table.push(newSlot);
		newA.lengths.push(newA.lengths[newA.lengths.length - 1] + length(newSlot));
		return newA;
	}
	else
	{
		return null;
	}
}
function push_ ( item , a ) { // Handle resursion stop at leaf level. if ( a . height === 0 ) { if ( a . table . length < M ) { var newA = { ctor : '_Array' , height : 0 , table : a . table . slice ( ) } ; newA . table . push ( item ) ; return newA ; } else { return null ; } } // Recursively push var pushed = push_ ( item , botRight ( a ) ) ; // There was space in the bottom right tree, so the slot will // be updated. if ( pushed !== null ) { var newA = nodeCopy ( a ) ; newA . table [ newA . table . length - 1 ] = pushed ; newA . lengths [ newA . lengths . length - 1 ] ++ ; return newA ; } // When there was no space left, check if there is space left // for a new slot with a tree which contains only the item // at the bottom. if ( a . table . length < M ) { var newSlot = create ( item , a . height - 1 ) ; var newA = nodeCopy ( a ) ; newA . table . push ( newSlot ) ; newA . lengths . push ( newA . lengths [ newA . lengths . length - 1 ] + length ( newSlot ) ) ; return newA ; } else { return null ; } }
Recursively tries to push an item to the bottom-right most tree possible. If there is no space left for the item, null will be returned.
Recursively tries to push an item to the bottom - right most tree possible . If there is no space left for the item null will be returned .