Skip to content

Instantly share code, notes, and snippets.

@AyrA
Created October 18, 2017 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AyrA/636a16ef0ec1df74c03bd453a551a63d to your computer and use it in GitHub Desktop.
Save AyrA/636a16ef0ec1df74c03bd453a551a63d to your computer and use it in GitHub Desktop.
You no longer need an npm module to calculate squares of numbers
//Calculates x² of an integer up to ±1 million
var square = (function () {
var s = "if(A==B){return C;}";
var func = "var A=Math.abs(D|0);";
for (var i = 0; i <= 1000000; i++) {
func += s.replace(/B/, i).replace(/C/, i * i);
}
return new Function("D", func + "return Infinity;");
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment