@@ -255,15 +255,27 @@ Elm.Native.Array.make = function(elm) {
255255 }
256256
257257 function foldl(f, b, a) {
258− for (var i = 0; i < a.table.length; i++) {
259− b = A2(f, a.height == 0 ? a.table[i] : foldl(f, b, a.table[i]), b);
258+ if (a.height == 0) {
259+ for (var i = 0; i < a.table.length; i++) {
260+ b = A2(f, a.table[i], b);
261+ }
262+ } else {
263+ for (var i = 0; i < a.table.length; i++) {
264+ b = foldl(f, b, a.table[i]);
265+ }
260266 }
261267 return b;
262268 }
263269
264270 function foldr(f, b, a) {
265− for (var i = a.table.length; i--; ) {
266− b = A2(f, a.height == 0 ? a.table[i] : foldr(f, b, a.table[i]), b);
271+ if (a.height == 0) {
272+ for (var i = a.table.length; i--; ) {
273+ b = A2(f, a.table[i], b);
274+ }
275+ } else {
276+ for (var i = a.table.length; i--; ) {
277+ b = foldl(f, b, a.table[i]);
278+ }
267279 }
268280 return b;
269281 }
@@ -345,9 +357,11 @@ Elm.Native.Array.make = function(elm) {
345357 // TODO: Add support for appending trees of different sizes. Current
346358 // behavior will just rise the lower tree and then append them.
347359 function append(a,b) {
348− if (b.height > a.height) { return append(parentise(a, b.height), b); }
349− if (a.height > b.height) { return append(a, parentise(b, a.height)); }
350− if (a.height == 0) { return append(parentise(a, 1), parentise(b, 1)); }
360+ if (a.table.length == 0) return b;
361+ if (b.table.length == 0) return a;
362+ if (b.height > a.height) return append(parentise(a, b.height), b);
363+ if (a.height > b.height) return append(a, parentise(b, a.height));
364+ if (a.height == 0) return append(parentise(a, 1), parentise(b, 1));
351365
352366 var c = append_(a, b);
353367 if (c[1].table.length > 0) {