Created
November 2, 2024 12:22
-
-
Save kaineer/e84f9d2bfdbf3840cfb5e2788e550eab to your computer and use it in GitHub Desktop.
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
const context = ['sin', 'cos', 'exp'] | |
.map((name) => ('const ' + name + ' = Math.' + name + '; ')) | |
.join(''); | |
export const buildFunction = (fn: string): (x: number) => number => { | |
const fullFn = '(x) => { ' + context + ' return (' + fn + '); }'; | |
return eval(fullFn); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment