Created
October 18, 2017 14:52
-
-
Save AyrA/636a16ef0ec1df74c03bd453a551a63d to your computer and use it in GitHub Desktop.
You no longer need an npm module to calculate squares of numbers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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