Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
Fixes these bugs:
- #12 - Array.y() cuts off if an item is longer than the previous
- #14 - Array.z() ignores input other than 1,2,3

To be specific, Array.z() now performs positive-modulo by 4 before running. 0 returns the original, -1 is run as 3, 5 is run as 1, etc.
  • Loading branch information
ETHproductions committed Dec 28, 2015
1 parent cd3bf4c commit 742ef15
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/japt-interpreter.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ df(Array,'u',function(x){return this.unshift(x)});
df(Array,'v',function(){return this.shift()});
df(Array,'w',function(){return this.reverse()});
df(Array,'x',function(){return this.reduce(function(a,b){return a+parseFloat(b)},0)});
df(Array,'y',function(){var t="string"==typeof this[0][0],n=t?this.map(function(t){return t.split("")}):this;return n[0].map(function(r,i){return n.map(function(t){return t[i]})[t?"join":"valueOf"]("")})});
df(Array,'z',function(n){return n==1?this.y().map(f=function(l){return l.w()}):n==2?this.w().map(f):n==3?this.map(f).y():this.z(1)}); // (clockwise) 1: 90deg, 2: 180deg, 3: -90deg
df(Array,'y',function(){var t="string"==typeof this[0],n=t?this.map(function(t){return t.split("")}):this,x,y,z=n.reduce(function(p,q){return Math.max(p,q.length)},0),a=[];for(y=0;y<z;y++)a[y]=t?Array(n.length).fill(" "):[];for(y=0;y<n.length;y++)for(x=0;x<n[y].length;x++)a[x][y]=n[y][x];return t?a.map(function(r){var i=0;return r.join("")}):a});
df(Array,'z',function(n){if((typeof n)!="number")n=1;n%=4;if(n<0)n+=4;var f=function(l){return l.w()};return n==1?this.y().map(f):n==2?this.w().map(f):n==3?this.map(f).y():this}); // (clockwise) 1: 90deg, 2: 180deg, 3: -90deg
df(Array,'\u00E0',function(x){var f=function(y,z,a){if(y.length===0&&z.length===0)return;if(z.length===0){a.push(y)}else{var n=y.slice(0);n.push(z[0]);f(n,z.slice(1),a);f(y,z.slice(1),a)}return a};return f([],this,[]).filter(function(z){return x?z.length===x:1})});
df(Array,'\u00E1',function(x){var p=[],u=[],f=function(z){var c,i;for(i=0;i<z.length;i++){c=z.splice(i,1)[0];u.push(c);if(z.length===0)p.push(u.slice());f(z);z.splice(i,0,c);u.pop()}return p};var l;return f(this).map(function(z){return z.slice(0,x||z.length)})["\u00E2"]()});
df(Array,'\u00E2',function(){var u={},a=[];for(var i of this)if(!u.hasOwnProperty(i))u[i]=1,a.push(i);return a});
Expand Down Expand Up @@ -652,4 +652,4 @@ function evalJapt(code, before, onsuccess, onerror) {
} catch (e) {
if (onerror) onerror(e);
}
}
}

0 comments on commit 742ef15

Please sign in to comment.