From 223f6dbc196b309312750eabaab31018409a7113 Mon Sep 17 00:00:00 2001 From: Justin Date: Sun, 23 Jul 2017 00:01:19 -0400 Subject: [PATCH] Fixed Number.k() bug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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". --- src/japt-interpreter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/japt-interpreter.js b/src/japt-interpreter.js index a779954..58bdc38 100755 --- a/src/japt-interpreter.js +++ b/src/japt-interpreter.js @@ -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=1r?n:x);d=(x!=n);n/=x;}return f}); +df(Number,'k',function(){var n=+this,r,f=[],x,d=1r?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});