562 B
562 B
Parse an expression
An arithmetical expression consists of 2 numbers and an operator between them, for instance:
1 + 21.2 * 3.4-3 / -6-2 - 2
The operator is one of: "+", "-", "*" or "/".
There may be extra spaces at the beginning, at the end or between the parts.
Create a function parse(expr) that takes an expression and returns an array of 3 items:
- The first number.
- The operator.
- The second number.
For example:
let [a, op, b] = parse("1.2 * 3.4");
alert(a); // 1.2
alert(op); // *
alert(b); // 3.4