@@ -14,7 +14,7 @@ var slice = Array..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 |
|
@@ -63,15 +63,15 @@ jStat.fn = jStat. = {
|
63 | 63 | if ( isArray( args[0] )) {
|
64 | 64 | if ( isArray( args[0][0] )) {
|
65 | 65 | for ( var i = 0; i < args[0].length; i++ ) {
|
66 |
| -this.push( args[0][i] ); |
| 66 | +this[i] = args[0][i]; |
67 | 67 | }
|
68 | 68 | } else {
|
69 |
| -this.push( args[0] ); |
| 69 | +this[0] = args[0]; |
70 | 70 | }
|
71 | 71 |
|
72 | 72 | // if first argument is number, assume creation of sequence
|
73 | 73 | } else if ( !isNaN( args[0] )) {
|
74 |
| -this.push( jStat.seq.apply( null, args )); |
| 74 | +this[0] = jStat.seq.apply( null, args ); |
75 | 75 | }
|
76 | 76 | return this;
|
77 | 77 | },
|
@@ -244,18 +244,12 @@ jStat.extend({
|
244 | 244 |
|
245 | 245 | // map a function to a matrix or vector
|
246 | 246 | 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, |
251 | 248 | 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 ); |
259 | 253 | return res;
|
260 | 254 | },
|
261 | 255 |
|
|
0 commit comments