@@ -14,7 +14,7 @@ var slice = Array.prototype.slice,
14
14
descNum = function ( a , b ) { return b - a ; } ,
15
15
16
16
// test if array
17
- isArray = function ( arg ) {
17
+ isArray = Array . isArray || function ( arg ) {
18
18
return toString . call ( arg ) === "[object Array]" ;
19
19
} ,
20
20
@@ -42,15 +42,15 @@ jStat.fn = jStat.prototype = {
42
42
if ( isArray ( args [ 0 ] ) ) {
43
43
if ( isArray ( args [ 0 ] [ 0 ] ) ) {
44
44
for ( var i = 0 ; i < args [ 0 ] . length ; i ++ ) {
45
- this . push ( args [ 0 ] [ i ] ) ;
45
+ this [ i ] = args [ 0 ] [ i ] ;
46
46
}
47
47
} else {
48
- this . push ( args [ 0 ] ) ;
48
+ this [ 0 ] = args [ 0 ] ;
49
49
}
50
50
51
51
// if first argument is number, assume creation of sequence
52
52
} else if ( ! isNaN ( args [ 0 ] ) ) {
53
- this . push ( jStat . seq . apply ( null , args ) ) ;
53
+ this [ 0 ] = jStat . seq . apply ( null , args ) ;
54
54
}
55
55
return this ;
56
56
} ,
@@ -223,18 +223,12 @@ jStat.extend({
223
223
224
224
// map a function to a matrix or vector
225
225
map : function ( arr , func , toAlter ) {
226
- arr = isArray ( arr [ 0 ] ) ? arr : [ arr ] ;
227
- var row = 0 ,
228
- nrow = arr . length ,
229
- ncol = arr [ 0 ] . length ,
226
+ var len = arr . length ,
230
227
res = toAlter ? arr : [ ] ,
231
- col ;
232
- for ( ; row < nrow ; row ++ ) {
233
- res [ row ] = res [ row ] || [ ] ;
234
- for ( col = 0 ; col < ncol ; col ++ ) {
235
- res [ row ] [ col ] = func ( arr [ row ] [ col ] , row , col ) ;
236
- }
237
- }
228
+ i = 0 ;
229
+ for ( ; i < len ; i ++ )
230
+ if ( isArray ( arr [ i ] ) ) res [ i ] = jStat . map ( arr [ i ] , func , toAlter ) ;
231
+ else res [ i ] = func ( arr [ i ] , i , arr ) ;
238
232
return res ;
239
233
} ,
240
234
0 commit comments