diff --git a/src/lesson2/engine.test.ts b/src/lesson2/engine.test.ts index eae1cc00..03d27184 100644 --- a/src/lesson2/engine.test.ts +++ b/src/lesson2/engine.test.ts @@ -1,47 +1,116 @@ -import { firstPrioritiesCalc, secondPrioritiesCalc } from "./engine"; +import { + bracketsProcessing, + firstPrioritiesCalc, + secondPrioritiesCalc, + thirdPrioritiesCalc, + fourthPrioritiesCalc, +} from "./engine"; -describe("firstPrioritiesCalc simple cases", () => { - it("[1, * 32]", () => { - expect(firstPrioritiesCalc([1, "*", 32])).toEqual([32]); - }); - - it("[32, /, 32]", () => { - expect(firstPrioritiesCalc([32, "/", 32])).toEqual([1]); +describe("brackets processing simple cases", () => { + it("(5, +, 4, ), /, (, 5, -, 3, )", () => { + expect( + bracketsProcessing(["(", 5, "+", 4, ")", "/", "(", 5, "-", 3, ")"]) + ).toEqual([9, "/", 2]); }); +}); - it("[32, + 32]", () => { - expect(firstPrioritiesCalc([32, "+", 32])).toEqual([32, "+", 32]); +describe("brackets processing simple cases", () => { + it("(5+5)", () => { + expect(bracketsProcessing(["(", 5, "+", 5, ")"])).toEqual([10]); }); }); -describe("firstPrioritiesCalc mixed with second priorities cases", () => { - it("[32, /, 32, +, 10, *, 10]", () => { - expect(firstPrioritiesCalc([32, "/", 32, "+", 10, "*", 10])).toEqual([ - 1, - "+", - 100, +describe("brackets processing simple cases", () => { + it("sin ( 45 + 1 )", () => { + expect(bracketsProcessing(["sin", "(", 45, "+", 1, ")"])).toEqual([ + "sin", + 46, ]); }); }); -describe("secondPrioritiesCalc invalid cases", () => { - it("[32, / 32]", () => { - expect(() => secondPrioritiesCalc([32, "/", 32])).toThrow( - TypeError("Unexpected stack!") - ); +describe("brackets processing simple cases", () => { + it("1 + (3 + 2 * (3 + 4))", () => { + expect( + bracketsProcessing([ + 1, + "+", + "(", + 3, + "+", + 2, + "*", + "(", + 3, + "+", + 4, + ")", + ")", + ]) + ).toEqual([1, "+", 17]); }); }); +describe("firstPrioritiesCalc simple cases", () => { + it("sin 45", () => { + expect(firstPrioritiesCalc(["sin", 45])).toEqual([0.85]); + }); + it("cos 45", () => { + expect(firstPrioritiesCalc(["cos", 45])).toEqual([0.53]); + }); + it("tan 45", () => { + expect(firstPrioritiesCalc(["tan", 45])).toEqual([1.62]); + }); + it("sin 45 + 2", () => { + expect(firstPrioritiesCalc(["sin", 45, "+", 2])).toEqual([0.85, "+", 2]); + }); +}); describe("secondPrioritiesCalc simple cases", () => { - it("[32, + 32]", () => { - expect(secondPrioritiesCalc([32, "+", 32])).toEqual(64); + it("5, +, 4, /, 1, -, 3, **", () => { + expect(secondPrioritiesCalc([5, "+", 4, "/", 1, "-", 3, "**"])).toEqual([ + 5, + "+", + 4, + "/", + 1, + "-", + 9, + ]); + }); + it("3, **", () => { + expect(secondPrioritiesCalc([3, "**", "+", 4, "^", 3])).toEqual([ + 9, + "+", + 4, + "^", + 3, + ]); }); +}); - it("[32, - 32]", () => { - expect(secondPrioritiesCalc([32, "-", 32])).toEqual(0); +describe("thirdPrioritiesCalc simple cases", () => { + it("2, '*', 4, '/', 1", () => { + expect(thirdPrioritiesCalc([2, "*", 4, "/", 1])).toEqual([8]); + }); + it("2, '*', 4, '/', 1, -, 2, ^, 4", () => { + expect( + thirdPrioritiesCalc([2, "*", 4, "/", 1, "-", 2, "^", 4, "+", 1]) + ).toEqual([8, "-", 16, "+", 1]); + }); + it("2, '*', 4, '/', 1 - 2", () => { + expect(thirdPrioritiesCalc([2, "*", 4, "/", 1, "-", 2])).toEqual([ + 8, + "-", + 2, + ]); }); +}); - it("[32, - 32, +, 10]", () => { - expect(secondPrioritiesCalc([32, "-", 32, "+", 10])).toEqual(10); +describe("fourthPrioritiesCalc simple cases", () => { + it("2, '+', 4, '-', 1", () => { + expect(fourthPrioritiesCalc([2, "+", 4, "-", 1])).toEqual(5); + }); + it("2, '-', 4, '-', 10", () => { + expect(fourthPrioritiesCalc([2, "-", 4, "-", 10.5])).toEqual(-12.5); }); }); diff --git a/src/lesson2/engine.ts b/src/lesson2/engine.ts index 78aee1d7..6616415c 100644 --- a/src/lesson2/engine.ts +++ b/src/lesson2/engine.ts @@ -1,25 +1,43 @@ import { ParsedLineType } from "./parser"; import { isNumber } from "./helpers"; +import { calc } from "./runner"; import { mathOperators, mathPriorities, mathOperatorsPriorities, + functionMathOperators, + trigonometryMathOperators, } from "./mathOperators"; -const [FIRST, SECOND] = mathPriorities; +const [FIRST, SECOND, THIRD, FOURTH] = mathPriorities; + +export const bracketsProcessing = (stack: ParsedLineType): ParsedLineType => { + let indexOpenBrackets: number; + stack.forEach((item, index) => { + if (item === "(") { + indexOpenBrackets = index; + } + if (item === ")") { + stack.splice( + indexOpenBrackets, + index - indexOpenBrackets + 1, + calc(stack.slice(indexOpenBrackets + 1, index)) + ); + bracketsProcessing(stack); + } + }); + + return stack; +}; export const firstPrioritiesCalc = (stack: ParsedLineType): ParsedLineType => stack.reduce((result, nextItem) => { - const prevItem = result[result.length - 2]; const item = result[result.length - 1]; if (!isNumber(String(item)) && mathOperatorsPriorities[item] === FIRST) { - if (!mathOperators[item]) { - throw new TypeError("Unexpected stack!"); - } result = [ - ...result.slice(0, -2), - mathOperators[item](Number(prevItem), Number(nextItem)), + ...result.slice(0, -1), + trigonometryMathOperators[item](Number(nextItem)), ]; } else { result.push(nextItem); @@ -27,16 +45,40 @@ export const firstPrioritiesCalc = (stack: ParsedLineType): ParsedLineType => return result; }, []); -export const secondPrioritiesCalc = (stack: ParsedLineType): number => - stack.reduce((result, nextItem, key) => { - const item = stack[key - 1]; +export const secondPrioritiesCalc = (stack: ParsedLineType): ParsedLineType => + stack.reduce((result, item) => { + const prevItem = result[result.length - 1]; - if (mathOperatorsPriorities[item] === FIRST) { - throw new TypeError("Unexpected stack!"); + if (!isNumber(String(item)) && mathOperatorsPriorities[item] === SECOND) { + result = [ + ...result.slice(0, -1), + functionMathOperators[item](Number(prevItem)), + ]; + } else { + result.push(item); } + return result; + }, []); +export const thirdPrioritiesCalc = (stack: ParsedLineType): ParsedLineType => + stack.reduce((result, nextItem) => { + const prevItem = result[result.length - 2]; + const item = result[result.length - 1]; - if (!isNumber(String(item)) && mathOperatorsPriorities[item] === SECOND) { - result = mathOperators[item](Number(result), Number(nextItem)); + if (!isNumber(String(item)) && mathOperatorsPriorities[item] === THIRD) { + result = [ + ...result.slice(0, -2), + mathOperators[item](Number(prevItem), Number(nextItem)), + ]; + } else { + result.push(nextItem); } return result; + }, []); +export const fourthPrioritiesCalc = (stack: ParsedLineType): number => + stack.reduce((result, nextItem, key) => { + const item = stack[key - 1]; + if (!isNumber(String(item)) && mathOperatorsPriorities[item] === FOURTH) { + result = mathOperators[item](Number(result), Number(nextItem)); + } + return Number(result.toFixed(2)); }, Number(stack[0])); diff --git a/src/lesson2/helpers.ts b/src/lesson2/helpers.ts index b5a4b6ae..38a7cd2a 100644 --- a/src/lesson2/helpers.ts +++ b/src/lesson2/helpers.ts @@ -1 +1,2 @@ -export const isNumber = (item: string): boolean => !isNaN(Number(item)); +export const isNumber = (item: string): boolean => + !isNaN(Number(item)) && item !== ""; diff --git a/src/lesson2/index.ts b/src/lesson2/index.ts index 1766cf85..41c8a671 100644 --- a/src/lesson2/index.ts +++ b/src/lesson2/index.ts @@ -10,7 +10,7 @@ const rl = createInterface({ const question = (): Promise => new Promise((resolve) => { rl.question("> ", (answer: string) => { - const result = runner(answer); + const result = runner(answer.trim()); if (result) { console.log(`Result: ${result}`); diff --git a/src/lesson2/mathOperators.test.ts b/src/lesson2/mathOperators.test.ts index aad07e8d..bfe949c4 100644 --- a/src/lesson2/mathOperators.test.ts +++ b/src/lesson2/mathOperators.test.ts @@ -1,8 +1,19 @@ -import { mul, div, add, minus } from "./mathOperators"; +import { + mul, + div, + add, + minus, + pow, + square, + factorial, + sin, + cos, + tan, +} from "./mathOperators"; describe("mathOperators test cases", () => { it("mul 1 * 2 to equal 2", () => { - expect(mul(1, 2)).toBe(2); + expect(mul(1, 3)).toBe(3); }); it("mul 2 * 2 to equal 4", () => { @@ -24,4 +35,36 @@ describe("mathOperators test cases", () => { it("minus 4 - 2 to equal 2", () => { expect(minus(4, 2)).toBe(2); }); + + it("pow 2 in 3 equal 8", () => { + expect(pow(2, 3)).toBe(8); + }); + + it("square 4 equal 16", () => { + expect(square(4)).toBe(16); + }); + + it("square 2 equal 4", () => { + expect(square(2)).toBe(4); + }); + + it("factorial 5 equal 25", () => { + expect(factorial(5)).toBe(25); + }); + + it("sin 45 equal 0.82", () => { + expect(sin(45)).toBe(0.85); + }); + + it("sin 45 equal 0.82", () => { + expect(sin(45)).toBe(0.85); + }); + + it("cos 45 equal 0.53", () => { + expect(cos(45)).toBe(0.53); + }); + + it("tan 45 equal 0.53", () => { + expect(tan(45)).toBe(1.62); + }); }); diff --git a/src/lesson2/mathOperators.ts b/src/lesson2/mathOperators.ts index af8eb770..ef12c05f 100644 --- a/src/lesson2/mathOperators.ts +++ b/src/lesson2/mathOperators.ts @@ -1,4 +1,5 @@ export type ScalarOperationType = (first: number, second: number) => number; +export type FunctionOperationType = (first: number, second?: number) => number; export const mul: ScalarOperationType = ( first: number, @@ -20,20 +21,63 @@ export const minus: ScalarOperationType = ( second: number ): number => first - second; -export const mathOperators: { [key: string]: ScalarOperationType } = { +export const pow: FunctionOperationType = ( + first: number, + second?: number +): number => Math.pow(first, Number(second)); + +export const square: FunctionOperationType = (value: number): number => + pow(value, 2); +export const factorial: FunctionOperationType = (value: number): number => + pow(value, 2); +export const sin: FunctionOperationType = (value: number): number => + Number(Math.sin(value).toFixed(2)); +export const cos: FunctionOperationType = (value: number): number => + Number(Math.cos(value).toFixed(2)); +export const tan: FunctionOperationType = (value: number): number => + Number(Math.tan(value).toFixed(2)); +export const scalarMathOperators: { [key: string]: ScalarOperationType } = { "*": mul, "/": div, "+": add, "-": minus, + "^": pow, +}; + +export const functionMathOperators: { [key: string]: FunctionOperationType } = { + "**": square, + "!": factorial, +}; + +export const trigonometryMathOperators: { + [key: string]: FunctionOperationType; +} = { + sin: sin, + cos: cos, + tan: tan, +}; + +export const mathOperators: { + [key: string]: FunctionOperationType | ScalarOperationType; +} = { + ...scalarMathOperators, + ...functionMathOperators, + ...trigonometryMathOperators, }; -export const mathPriorities: number[] = [1, 2]; +export const mathPriorities: number[] = [1, 2, 3, 4]; -const [FIRST, SECOND] = mathPriorities; +const [FIRST, SECOND, THIRD, FOURTH] = mathPriorities; export const mathOperatorsPriorities: { [key: string]: number } = { - "*": FIRST, - "/": FIRST, - "+": SECOND, - "-": SECOND, + "*": THIRD, + "/": THIRD, + "+": FOURTH, + "-": FOURTH, + "^": THIRD, + "**": SECOND, + "!": SECOND, + sin: FIRST, + cos: FIRST, + tan: FIRST, }; diff --git a/src/lesson2/parser.test.ts b/src/lesson2/parser.test.ts index 5593e312..47a06d84 100644 --- a/src/lesson2/parser.test.ts +++ b/src/lesson2/parser.test.ts @@ -12,6 +12,83 @@ describe("Parser correct cases", () => { it("1 + 32 - 2 + 2", () => { expect(parser("1 + 32 - 2 + 2")).toEqual([1, "+", 32, "-", 2, "+", 2]); }); + + it("2 ** + 2 / 3", () => { + expect(parser("2 ** + 2 / 3")).toEqual([2, "**", "+", 2, "/", 3]); + }); + + // brackets + it("(5.2 + 3.2)", () => { + expect(parser("(5.2 + 3.2)")).toEqual(["(", 5.2, "+", 3.2, ")"]); + }); + it("8 + (6 * 3)", () => { + expect(parser("8 + (6 * 3)")).toEqual([8, "+", "(", 6, "*", 3, ")"]); + }); + + it("7 + (8 + 9 * 2) * 3 - ((1)) / (5 * (5 + 2))", () => { + expect(parser("7 + (8 + 9 * 2) * 3 - ((1)) / (5 * (5 + 2))")).toEqual([ + 7, + "+", + "(", + 8, + "+", + 9, + "*", + 2, + ")", + "*", + 3, + "-", + "(", + "(", + 1, + ")", + ")", + "/", + "(", + 5, + "*", + "(", + 5, + "+", + 2, + ")", + ")", + ]); + }); + it("5 + (3)", () => { + expect(parser("5 + (3)")).toEqual([5, "+", "(", 3, ")"]); + }); + + it("5 + ((3))", () => { + expect(parser("5 + ((3))")).toEqual([5, "+", "(", "(", 3, ")", ")"]); + }); + + it("5 + (((3)))", () => { + expect(parser("5 + (3 * 2)")).toEqual([5, "+", "(", 3, "*", 2, ")"]); + }); + + it("5 + ((3 + 6) * 2) / 2", () => { + expect(parser("5 + ((3 + 6) * 2) / 2")).toEqual([ + 5, + "+", + "(", + "(", + 3, + "+", + 6, + ")", + "*", + 2, + ")", + "/", + 2, + ]); + }); + + it("(-5.2 + 3)", () => { + expect(parser("(-5.2 + 3)")).toEqual(["(", -5.2, "+", 3, ")"]); + }); }); describe("Parser invalid cases", () => { @@ -20,8 +97,56 @@ describe("Parser invalid cases", () => { TypeError("Unexpected string") ); }); - - it("1 ! 33 - 2", () => { - expect(() => parser("1 ! 33 - 2")).toThrow(TypeError("Unexpected string")); + it("1 ! 33 -", () => { + expect(() => parser("1 ! 33 -")).toThrow(TypeError("Unexpected string")); + }); + it("** ** **", () => { + expect(() => parser("** ** **")).toThrow(TypeError("Unexpected string")); + }); + it("** 2", () => { + expect(() => parser("** 2")).toThrow(TypeError("Unexpected string")); + }); + it("7 + ((8 * 9) - 3", () => { + expect(() => parser("7 + ((8 * 9) - 3")).toThrow( + TypeError("Unexpected string") + ); + }); + it("7 + (8 * 9)) - 3", () => { + expect(() => parser("7 + (8 * 9)) - 3")).toThrow( + TypeError("Unexpected string") + ); + }); + it("7 + (8 * 9)) - 3", () => { + expect(() => parser("7 + (8 * 9)) - 3")).toThrow( + TypeError("Unexpected string") + ); + }); + it("7 + 2 () + 1", () => { + expect(() => parser("7 + 2 () + 1")).toThrow( + TypeError("Unexpected string") + ); + }); + it("5 + ()3)", () => { + expect(() => parser("5 + ()3)")).toThrow(TypeError("Unexpected string")); + }); + it("5 + ()3", () => { + expect(() => parser("5 + ()3")).toThrow(TypeError("Unexpected string")); + }); + it("5 + )3(", () => { + expect(() => parser("5 + )3(")).toThrow(TypeError("Unexpected string")); + }); + it("(5 + 3))", () => { + expect(() => parser("(5 + 3))")).toThrow(TypeError("Unexpected string")); + }); + it("(5.2w + 3)", () => { + expect(() => parser("(5.2w + 3)")).toThrow(TypeError("Unexpected string")); + }); + it("1 + (1+) - 33", () => { + expect(() => parser("1 + (1 + ы) - 33")).toThrow( + TypeError("Unexpected string") + ); + }); + it("5 + (3))", () => { + expect(() => parser("5 + (3))")).toThrow(TypeError("Unexpected string")); }); }); diff --git a/src/lesson2/parser.ts b/src/lesson2/parser.ts index 118ff662..1874ceab 100644 --- a/src/lesson2/parser.ts +++ b/src/lesson2/parser.ts @@ -1,24 +1,117 @@ import { isNumber } from "./helpers"; -import { mathOperators } from "./mathOperators"; +import { + functionMathOperators, + scalarMathOperators, + trigonometryMathOperators, + mathOperators, +} from "./mathOperators"; export type ParsedLineType = (number | string)[]; -export const parser = (line: string): ParsedLineType | null => { +export const parser = (line: string): ParsedLineType => { + let _countOpenBrackets = 0; + let _countCloseBrackets = 0; + for (let i = 0; i < line.length; i++) { + if (line[i] === ")") { + _countCloseBrackets++; + } + if (line[i] === "(") { + _countOpenBrackets++; + } + } + if (_countOpenBrackets !== _countCloseBrackets) { + throw new TypeError("Unexpected string"); + } const stack = line.split(" "); - return stack.reduce((result, item, key) => { + if ( + key === 0 && + mathOperators.hasOwnProperty(item) && + !trigonometryMathOperators.hasOwnProperty(item) + ) { + throw new TypeError("Unexpected string"); + } + + if (key === stack.length - 1 && scalarMathOperators.hasOwnProperty(item)) { + throw new TypeError("Unexpected string"); + } const prevItem = stack[key - 1]; + const nextItem = stack[key + 1]; + let itemHasCloseBrackets = false; + let countOpenBrackets = 0; + let countCloseBrackets = 0; + + if (item.length > 1 && (item.includes("(") || item.includes(")"))) { + let numberInsideBrackets = false; + const itemLength = item.length; + const oldItem = item; + + for (let i = 0; i < itemLength; i++) { + const curSymbol = oldItem[i]; + if (curSymbol === "(") { + countOpenBrackets++; + item = item.replace("(", ""); + } + if (curSymbol === ")") { + if (i == 0) { + throw new TypeError("Unexpected string"); + } + if (countOpenBrackets !== 0 && !numberInsideBrackets) { + throw new TypeError("Unexpected string"); + } + countCloseBrackets++; + item = item.replace(")", ""); + itemHasCloseBrackets = true; + } + if (isNumber(curSymbol)) { + numberInsideBrackets = true; + } + } + + if (countOpenBrackets > 0) { + for (let i = 0; i < countOpenBrackets; i++) { + result.push("("); + } + } + + if (isNumber(item)) { + stack[key] = item; + } + } const isValidNumberPush = !isNumber(prevItem) && isNumber(item); + const isValidFunctionalOperatorPush = + isNumber(prevItem) && functionMathOperators.hasOwnProperty(item); + + const isValidTrigonometryOperatorPush = + (isNumber(nextItem) && trigonometryMathOperators.hasOwnProperty(item)) || + ((String(nextItem).indexOf("(") !== -1 || + String(nextItem).indexOf(")") !== -1) && + trigonometryMathOperators.hasOwnProperty(item)); + + const isValidScalarOperatorPush = + (isNumber(prevItem) && scalarMathOperators.hasOwnProperty(item)) || + (functionMathOperators.hasOwnProperty(prevItem) && + scalarMathOperators.hasOwnProperty(item)); + const isValidOperatorPush = - isNumber(prevItem) && - !isNumber(item) && - mathOperators.hasOwnProperty(item); + isValidScalarOperatorPush || + isValidFunctionalOperatorPush || + isValidTrigonometryOperatorPush; + + const isValidBrackets = item.length === 1 && (item === "(" || item === ")"); if (isValidNumberPush) { result.push(Number(item)); + if (itemHasCloseBrackets) { + for (let i = 0; i < countCloseBrackets; i++) { + result.push(")"); + } + } } else if (isValidOperatorPush) { result.push(item); + } else if (isValidBrackets) { + result.push(item); } else { throw new TypeError("Unexpected string"); } diff --git a/src/lesson2/runner.test.ts b/src/lesson2/runner.test.ts index 1318dce3..5bd8f7f8 100644 --- a/src/lesson2/runner.test.ts +++ b/src/lesson2/runner.test.ts @@ -12,6 +12,10 @@ describe("Runner simple cases", () => { it("2 + 32", () => { expect(runner("2 + 32")).toEqual(34); }); + + it("2**", () => { + expect(runner("2 **")).toEqual(4); + }); }); describe("Runner tripled/mixed cases", () => { @@ -37,3 +41,35 @@ describe("Runner long cases", () => { expect(runner("20 - 10 * 10 / 5 - 3")).toEqual(-3); }); }); + +describe("Runner with brackets cases", () => { + it("(2 + 2) * 2", () => { + expect(runner("(2 + 2) * 2")).toEqual(8); + }); +}); + +describe("Runner with brackets cases", () => { + it("((2 + 2)) ** * 2", () => { + expect(runner("(2 + 2) ** * 2")).toEqual(32); + }); +}); + +describe("Runner with brackets cases", () => { + it("8 * 4 + 3 * (4 + 8 - (2 ^ 3 + 1))", () => { + expect(runner("8 * 4 + 3 * (4 + 8 - (2 ^ 3 + 1))")).toEqual(41); + }); +}); + +describe("Runner with sin cases", () => { + it("sin ( 45 )", () => { + expect(runner("sin ( 45 )")).toEqual(0.85); + }); +}); + +describe("Runner with null cases", () => { + it("null", () => { + expect(() => { + runner(""); + }).toThrow("Unexpected string"); + }); +}); diff --git a/src/lesson2/runner.ts b/src/lesson2/runner.ts index 920249fd..9b173805 100644 --- a/src/lesson2/runner.ts +++ b/src/lesson2/runner.ts @@ -1,19 +1,37 @@ -import { parser } from "./parser"; +import { parser, ParsedLineType } from "./parser"; +import { + firstPrioritiesCalc, + secondPrioritiesCalc, + fourthPrioritiesCalc, + thirdPrioritiesCalc, + bracketsProcessing, +} from "./engine"; -import { firstPrioritiesCalc, secondPrioritiesCalc } from "./engine"; +export const calc = (stack: ParsedLineType): number => { + const bracketsProcessingRes = bracketsProcessing(stack); -export const runner = (line: string): number => { - const stack = parser(line); + const firstPrioritiesRes = firstPrioritiesCalc(bracketsProcessingRes); - if (stack === null) { - throw new TypeError("Unexpected string"); + if (firstPrioritiesRes.length === 1) { + return Number(firstPrioritiesRes[0]); } - const firstPrioritiesRes = firstPrioritiesCalc(stack); + const secondPrioritiesRes = secondPrioritiesCalc(firstPrioritiesRes); - if (firstPrioritiesRes.length === 1) { - return Number(firstPrioritiesRes[0]); + if (secondPrioritiesRes.length === 1) { + return Number(secondPrioritiesRes[0]); } - return secondPrioritiesCalc(firstPrioritiesRes); + const thirdPrioritiesRes = thirdPrioritiesCalc(secondPrioritiesRes); + + if (thirdPrioritiesRes.length === 1) { + return Number(thirdPrioritiesRes[0]); + } + + return fourthPrioritiesCalc(thirdPrioritiesRes); +}; +export const runner = (line: string): number => { + const stack = parser(line); + + return calc(stack); };