How do you divide an equation into numbers?

  • 0
    Hello everyone! An equation is entered into the input. When the button is pressed, it must be split into numbers with a sign in front of it For example the equation (I made it up myself): 59 + 3x-5 = 45 + 6x and js should divide it into:
    famous: 59, -5, 45
    unknown: + 3x, + 6x
    how to do it?
    JavaScript Lorelei Sherman, Oct 18, 2020

  • 1 Answers
  • 0
    You can get constants and variables, and solve it, with algebra.js :

    const left = new algebra.Expression('x')
    .multiply(3)
    .add(59)
    .subtract(5);

    const right = new algebra.Expression('x')
    .multiply(6)
    .add(45);

    const expression = new algebra.Equation(left, right);

    console.log(`${expression} => ${expression.solveFor('x')}`); // 3x + 54 = 6x + 45 => 3
    Molly Rowe

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!