I am looking to store various mathematical expressions that involve basic operations such as addition, subtraction, multiplication, division, exponents, square roots, grouping, etc., along with unique placeholders in the form of a string.
const json = {
“formula”: “{{a45bc2a1-ed82-4ccd-a455-f7959e875aad}}+({{f6c2ef2b-a4fa-4cfb-b62d-d0d7c3e266d9}}*{{335563ad-a715-47b9-8e54-2b8553768168}})”
}
The placeholders correspond to arrays like so:
const map = {
“a45bc2a1-ed82-4ccd-a455-f7959e875aad”: [1, 2, 3, 4, 5],
“f6c2ef2b-a4fa-4cfb-b62d-d0d7c3e266d9”: [10, 20, 30, 40, 50],
“335563ad-a715-47b9-8e54-2b8553768168”: [1, 2, 3, 4, 5]
}
Is there a way to accomplish this? The eval() function is not suitable for vector operations and I am uncertain about how to parse arbitrary formulas for element-wise calculations.
The expected output should be:
[11, 42, 93, 164, 255]