File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var slice = Array..slice,
1414
descNum = function( a, b ) { return b - a; },
1515

1616
// test if array
17-
isArray = function( arg ) {
17+
isArray = Array.isArray || function( arg ) {
1818
return toString.call( arg ) === "[object Array]";
1919
},
2020

@@ -63,15 +63,15 @@ jStat.fn = jStat. = {
6363
if ( isArray( args[0] )) {
6464
if ( isArray( args[0][0] )) {
6565
for ( var i = 0; i < args[0].length; i++ ) {
66-
this.push( args[0][i] );
66+
this[i] = args[0][i];
6767
}
6868
} else {
69-
this.push( args[0] );
69+
this[0] = args[0];
7070
}
7171

7272
// if first argument is number, assume creation of sequence
7373
} else if ( !isNaN( args[0] )) {
74-
this.push( jStat.seq.apply( null, args ));
74+
this[0] = jStat.seq.apply( null, args );
7575
}
7676
return this;
7777
},
@@ -244,18 +244,12 @@ jStat.extend({
244244

245245
// map a function to a matrix or vector
246246
map : function( arr, func, toAlter ) {
247-
arr = isArray( arr[0] ) ? arr : [ arr ];
248-
var row = 0,
249-
nrow = arr.length,
250-
ncol = arr[0].length,
247+
var len = arr.length,
251248
res = toAlter ? arr : [],
252-
col;
253-
for ( ; row < nrow; row++ ) {
254-
res[row] = res[row] || [];
255-
for ( col = 0; col < ncol; col++ ) {
256-
res[row][col] = func( arr[row][col], row, col );
257-
}
258-
}
249+
i = 0;
250+
for ( ; i < len; i++ )
251+
if ( isArray( arr[i] )) res[i] = jStat.map( arr[i], func, toAlter );
252+
else res[i] = func( arr[i], i, arr );
259253
return res;
260254
},
261255

0 commit comments

Comments
 (0)