Skip to content

Latest commit

 

History

History
19 lines (18 loc) · 1.7 KB

60-solve-for-x.md

File metadata and controls

19 lines (18 loc) · 1.7 KB

Problem:

Solve For X

You will be given an equation as a string and you will need to solve for X and return x's value. For example:

solveForX('x - 5 = 20'); // Should return 25
solveForX('20 = 5 * x - 5'); // Should return 5
solveForX('5 * x = x + 8'); // Should return 2
solveForX('(5 - 3) * x = x + 2'); // Should return 2
solve_for_x('x - 5 = 20') # should return 25
solve_for_x('20 = 5 * x - 5') # should return 5
solve_for_x('5 * x = x + 8') # should return 2
solve_for_x('(5 - 3) * x = x + 2') # should return 2

NOTES:

  • All numbers will be whole numbers
  • Don't forget about the order of operations.
  • If the random tests don't pass the first time, just run them again.

Solution