Skip to main content
Mod Removes Wiki by Doorknob
added 64 characters in body
Source Link
ajax333221
  • 3.7k
  • 3
  • 25
  • 29

In cases where you are using the ternary operator to chose between two numbers, and the conditional is either a boolean or number 1 or 0, you can do math operations instead:

In cases where you are using the ternary operator to chose between two numbers, you can do math operations instead:

In cases where you are using the ternary operator to chose between two numbers, and the conditional is either a boolean or number 1 or 0, you can do math operations instead:

added 334 characters in body
Source Link
ajax333221
  • 3.7k
  • 3
  • 25
  • 29

In cases where you are using the conditional check with a booleanternary operator to chose between two numbers, you can do math equationsoperations instead:

In case you don't find savings after running it with a JS compressor, simply use the former (x?y:z).

Note2: there is an isolated case where (x) !== (x?1:0), as x must be typeof === "number" for it to work. However, in the case of (-x) it works just fine.

Note3: In case you don't find savings, simply use the former (x?y:z)

Previously I thought method B couldn't ever beat A, however exceptions do exist:

I created a github project that makes the simplification for us (jsFiddle demo)

In cases where you are using the conditional check with a boolean to chose between two numbers, you can do math equations instead:

In case you don't find savings after running it with a JS compressor, simply use the former (x?y:z).

Previously I thought method B couldn't ever beat A, however exceptions do exist:

In cases where you are using the ternary operator to chose between two numbers, you can do math operations instead:

Note2: there is an isolated case where (x) !== (x?1:0), as x must be typeof === "number" for it to work. However, in the case of (-x) it works just fine.

Note3: In case you don't find savings, simply use the former (x?y:z)

Previously I thought method B couldn't ever beat A, however exceptions do exist:

I created a github project that makes the simplification for us (jsFiddle demo)

I found some cases where method B is actually better than A
Source Link
ajax333221
  • 3.7k
  • 3
  • 25
  • 29

Previously I thought method B couldn't ever beat A, however exceptions do exist:

(x?97:100) //original (-3*x+100) (3*!x+97) 

Previously I thought method B couldn't ever beat A, however exceptions do exist:

(x?97:100) //original (-3*x+100) (3*!x+97) 
I found some cases where method B is actually better than A
Source Link
ajax333221
  • 3.7k
  • 3
  • 25
  • 29
Loading
bad examples, y*(x?1:-1) is simply (x?y:-y)
Source Link
ajax333221
  • 3.7k
  • 3
  • 25
  • 29
Loading
added 22 characters in body
Source Link
ajax333221
  • 3.7k
  • 3
  • 25
  • 29
Loading
after some time I got really into it, thanks for the original idea original poster :)
Source Link
ajax333221
  • 3.7k
  • 3
  • 25
  • 29
Loading
Fixed an inaccuracy - it doesn't return 42 if a=2, then it'll return 84, obviously.
Source Link
kba
  • 101
  • 3
Loading
Source Link
mellamokb
  • 6.1k
  • 3
  • 28
  • 34
Loading