on master help sign in
Fix #620
commit52e70c8a9452b160597accc520788e38d3a0e8b6 authorChristian Widera <xash@posteo.de> dateTue 6 May 2014, 23:58 (12 years ago) parent24ab294
1 file changed+8−1
libraries/Native/Array.js+8−1
libraries/Native/Array.js+8−1
@@ -240,14 +240,21 @@ Elm.Native.Array.make = function(elm) {
240240
241241 // Maps a function over the elements with their index as first argument.
242242 function indexedMap(f, a) {
243+ return indexedMap_(f, a, 0);
244+ }
245+
246+ function indexedMap_(f, a, from) {
243247 var newA = { ctor:"_Array", height:a.height, table:new Array(a.table) };
244248 if (a.height > 0) { newA.lengths = a.lengths; }
245249 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]);
247253 }
248254 return newA;
249255 }
250256
257+
251258 function foldl(f, b, a) {
252259 for (var i = 0; i < a.table.length; i++) {
253260 b = A2(f, a.height == 0 ? a.table[i] : foldl(f, b, a.table[i]), b);