diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2020-08-08 13:55:05 -0400 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2020-08-08 13:55:05 -0400 |
| commit | b14a5f4ab8eb98fecbcd978f0715980edd112c7a (patch) | |
| tree | a3136b4264071dbf3c4fb860432243f23d28c846 | |
| parent | b82932e244f6670ec56e200740d1dacc70a80815 (diff) | |
Don't copy initial cell in scan with empty argument
| -rw-r--r-- | bqn.js | 11 |
1 files changed, 7 insertions, 4 deletions
@@ -86,10 +86,13 @@ let table = m1(f => (x,w) => !has(w) : arr([].concat.apply([],w.map(d=>x.map(e=>call(f,e,d)))),w.sh.concat(x.sh))); let scan = m1(f => (x,w) => { let s=x.sh;assert(!has(w)&&x.a&&s.length>0); - let c=1;for(let i=1;i<s.length;i++)c*=s[i]; - let l=x.length,r=Array(l),i=0; - for(;i<c;i++) r[i]=x[i]; - for(;i<l;i++) r[i]=call(f,x[i],r[i-c]); + let l=x.length,r=Array(l); + if (l>0) { + let c=1;for(let i=1;i<s.length;i++)c*=s[i]; + let i=0; + for(;i<c;i++) r[i]=x[i]; + for(;i<l;i++) r[i]=call(f,x[i],r[i-c]); + } return arr(r,s); }); |
