Skip to main content
3 of 4
added 140 characters in body
Shaggy
  • 43.5k
  • 4
  • 36
  • 94

#Use Exponents

If your language has an exponent operator you might be able to use it to generate, if not the number you want, at least a number you can perform a simple calculation or 2 on to arrive at your number. Even without an operator, you may still be able to save bytes with a built-in function or method.

##Example The maximum safe integer in JavaScript is 9007199254740991, which is 16 digits long. In ES7, this can be calculated with the following 7 bytes:

2**53-1

The equivalent in ES6 and earlier, while the same length as the integer itself in this instance, demonstrates that using a more verbose method might not necessarily cost you any bytes.

Math.pow(2,53)-1

The above, though, may work out shorter if, for example, you already have Math aliased to a single character elsewhere in your code.

Shaggy
  • 43.5k
  • 4
  • 36
  • 94