Created
March 17, 2018 10:43
-
-
Save techiepriyansh/92e04b8bfab9c3b294ffa4faca1cd6af to your computer and use it in GitHub Desktop.
The simplest way to parse string algebra in javascript with 3 lines of code. This magical thing uses javascript's inbuilt ability to parse string algebra...
This file contains 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
var makeFunctionOfX = function(src) { | |
return Function('x', 'return ' + src); | |
}; | |
var g = makeFunctionOfX('2 * x') | |
var y = g(3); // y contains 6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment