(input)
| 1 | export default class Parser { |
| 2 | parse(input) { |
| 3 | input = input.split(/\n/); |
| 4 | input = input.filter(line => line.trim()); |
| 5 | if (!input.every((line) => /\d+\s*[\+\-\*\/]\s*\d+\s*/gm.test(line))) { |
| 6 | throw new Error('Parse error'); |
| 7 | } |
| 8 | |
| 9 | return input.map((line) => { |
| 10 | const { groups } = |
| 11 | /(?<first_operand>\d+)\s*(?<operator>[\+\-\*\/])\s*(?<second_operand>\d+)/gm.exec( |
| 12 | line |
| 13 | ); |
| 14 | return { |
| 15 | firstOperand: Number(groups.first_operand), |
| 16 | operator: groups.operator, |
| 17 | secondOperand: Number(groups.second_operand), |
| 18 | }; |
| 19 | }); |
| 20 | } |
| 21 | } |
no outgoing calls
no test coverage detected