on master help sign in
Fix #620
52e70c8Christian Widera
libraries/Native/Array.js+8−1
@@ -240,14 +240,21 @@ Elm.Native.Array.make = function(elm) {
240
240
241 // Maps a function over the elements with their index as first argument.
241 // Maps a function over the elements with their index as first argument.
242 function indexedMap(f, a) {
242 function indexedMap(f, a) {
243+ return indexedMap_(f, a, 0);
244+ }
245+
246+ function indexedMap_(f, a, from) {
243 var newA = { ctor:"_Array", height:a.height, table:new Array(a.table) };
247 var newA = { ctor:"_Array", height:a.height, table:new Array(a.table) };
244 if (a.height > 0) { newA.lengths = a.lengths; }
248 if (a.height > 0) { newA.lengths = a.lengths; }
245 for (var i = 0; i < a.table.length; i++) {
249 for (var i = 0; i < a.table.length; i++) {
246− newA.table[i] = a.height == 0 ? A2(f, i, a.table[i]) : indexedMap(f, a.table[i]);
250+ newA.table[i] = a.height == 0 ? A2(f, from + i, a.table[i])
251+ : indexedMap_( f, a.table[i]
252+ , i == 0 ? 0 : a.lengths[i - 1]);
247 }
253 }
248 return newA;
254 return newA;
249 }
255 }
250
256
257+
251 function foldl(f, b, a) {
258 function foldl(f, b, a) {
252 for (var i = 0; i < a.table.length; i++) {
259 for (var i = 0; i < a.table.length; i++) {
253 b = A2(f, a.height == 0 ? a.table[i] : foldl(f, b, a.table[i]), b);
260 b = A2(f, a.height == 0 ? a.table[i] : foldl(f, b, a.table[i]), b);