File tree Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -269,13 +269,18 @@ jStat.extend({
269
269
270
270
// map a function to a matrix or vector
271
271
map : function ( arr , func , toAlter ) {
272
- var len = arr . length ,
272
+ if ( ! isArray ( arr [ 0 ] ) ) arr = [ arr ] ;
273
+ var row = 0 ,
274
+ nrow = arr . length ,
275
+ ncol = arr [ 0 ] . length ,
273
276
res = toAlter ? arr : [ ] ,
274
- i = 0 ;
275
- for ( ; i < len ; i ++ )
276
- if ( isArray ( arr [ i ] ) ) res [ i ] = jStat . map ( arr [ i ] , func , toAlter ) ;
277
- else res [ i ] = func ( arr [ i ] , i , arr ) ;
278
- return res ;
277
+ col ;
278
+ for ( ; row < nrow ; row ++ ) {
279
+ if ( ! res [ row ] ) res [ row ] = [ ] ;
280
+ for ( col = 0 ; col < ncol ; col ++ )
281
+ res [ row ] [ col ] = func ( arr [ row ] [ col ] , row , col ) ;
282
+ }
283
+ return res . length === 1 ? res [ 0 ] : res ;
279
284
} ,
280
285
281
286
// destructively alter an array
You can’t perform that action at this time.
0 commit comments