This commit is contained in:
Ilya Kantor 2019-09-06 01:15:24 +03:00
parent 20547570ff
commit 681cae4b6a
16 changed files with 505 additions and 362 deletions

View file

@ -0,0 +1,28 @@
# Parse an expression
An arithmetical expression consists of 2 numbers and an operator between them, for instance:
- `1 + 2`
- `1.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:
1. The first number.
2. The operator.
3. The second number.
For example:
```js
let [a, op, b] = parse("1.2 * 3.4");
alert(a); // 1.2
alert(op); // *
alert(b); // 3.4
```