Skip to content

Commit

Permalink
Fixed Number.k() bug
Browse files Browse the repository at this point in the history
When the result of Number.k() was a one-item array, that one item was a Number object instead of an ordinary number. This breaks code that checks for an item's existence in the array. For example, "2k ø2", which checks if the number 2 exists in the array of factors of 2, returns false when it should return true.

Example in Chrome dev console: http://i.imgur.com/4NawhOk.png

This was fixed similarly to how I see you handling some other Number functions: by casting the Number object to an ordinary number by using "+this".
  • Loading branch information
jmariner committed Jul 23, 2017
1 parent 3656c93 commit 223f6db
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/japt-interpreter.js
Expand Up @@ -237,7 +237,7 @@ df(Number,'g',function(){return this.toString()=="NaN"?"NaN":this<0?-1:this>0?1:
df(Number,'h',function(x){x=fb(x,1);return this.toPrecision(x)});
df(Number,'i',function(x){return Japt.intervals[Japt.intervals.length]=setInterval(x,this)});
df(Number,'j',function(){var n=+this;if(n===2)return true;if(n%1||n<2||n%2===0)return false;for(var i=3,s=Math.sqrt(n);i<=s;i+=2)if(n%i===0)return false;return true});
df(Number,'k',function(){var n=this,r,f=[],x,d=1<n;while(d){r=Math.sqrt(n);x=2;if(n%x){x=3;while(n%x&&((x+=2)<r));}f.push(x=x>r?n:x);d=(x!=n);n/=x;}return f});
df(Number,'k',function(){var n=+this,r,f=[],x,d=1<n;while(d){r=Math.sqrt(n);x=2;if(n%x){x=3;while(n%x&&((x+=2)<r));}f.push(x=x>r?n:x);d=(x!=n);n/=x;}return f});
df(Number,'l',function(){var n=Math.trunc(this),x=Math.trunc(this);if(n<1)return 1;while(--n)x*=n;return x});
df(Number,'m',function(){return[].reduce.call(arguments,function(x,y){return Math.min(x,y)},this)});
df(Number,'n',function(x){x=fb(x,0);return x-this});
Expand Down

0 comments on commit 223f6db

Please sign in to comment.