From e97929f41f5beb4c1498a765a6233cba3eedb050 Mon Sep 17 00:00:00 2001 From: Maxim Kremnev Date: Fri, 10 Jul 2020 11:13:43 +0300 Subject: [PATCH 1/2] Added functional calc --- package.json | 4 ++- src/lesson2/calc.test.ts | 11 +++++++++ src/lesson2/calc.ts | 17 +++++++++++++ src/lesson2/index.ts | 30 +++++++++++++++++++++++ src/lesson2/logic.test.ts | 15 ++++++++++++ src/lesson2/logic.ts | 46 +++++++++++++++++++++++++++++++++++ src/lesson2/operators.test.ts | 37 ++++++++++++++++++++++++++++ src/lesson2/operators.ts | 45 ++++++++++++++++++++++++++++++++++ src/lesson2/parser.test.ts | 37 ++++++++++++++++++++++++++++ src/lesson2/parser.ts | 21 ++++++++++++++++ 10 files changed, 262 insertions(+), 1 deletion(-) create mode 100644 src/lesson2/calc.test.ts create mode 100644 src/lesson2/calc.ts create mode 100644 src/lesson2/index.ts create mode 100644 src/lesson2/logic.test.ts create mode 100644 src/lesson2/logic.ts create mode 100644 src/lesson2/operators.test.ts create mode 100644 src/lesson2/operators.ts create mode 100644 src/lesson2/parser.test.ts create mode 100644 src/lesson2/parser.ts diff --git a/package.json b/package.json index 45909e2..20b9f8d 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "scripts": { "start": "npx webpack-dev-server --mode development --open --hot", "test": "npx jest", - "build": "npx webpack --mode production" + "build": "npx webpack --mode production", + "calc": "npx ts-node src/lesson2" }, "keywords": [ "calculation", @@ -30,6 +31,7 @@ "html-webpack-plugin": "^4.3.0", "jest": "^25.5.4", "prettier": "^2.0.5", + "ts-node": "^8.10.2", "typescript": "^3.9.5", "webpack": "^4.43.0", "webpack-cli": "^3.3.12", diff --git a/src/lesson2/calc.test.ts b/src/lesson2/calc.test.ts new file mode 100644 index 0000000..9682c2d --- /dev/null +++ b/src/lesson2/calc.test.ts @@ -0,0 +1,11 @@ +import { calc } from './calc'; + +describe('Positve test case', () => { + it('Extentions 2 + 2 + 2 = 6', () => { + expect(calc('2 + 2 + 2')).toBe(6); + }); + + it('Extentions 2** + 2 + 2 = 8', () => { + expect(calc('2** + 2 + 2')).toBe(8); + }); +}); diff --git a/src/lesson2/calc.ts b/src/lesson2/calc.ts new file mode 100644 index 0000000..da14f76 --- /dev/null +++ b/src/lesson2/calc.ts @@ -0,0 +1,17 @@ +import { parser } from './parser'; + +import { firstPrioritiesCalc, secondPrioritiesCalc, degreeСalc } from './logic'; + +export const calc = (extention: string): number => { + const parserExtention = parser(extention); + + const firstPrioritiesRes = parserExtention.includes('**') + ? degreeСalc(parserExtention) + : firstPrioritiesCalc(parserExtention); + + if (firstPrioritiesRes.length === 1) { + return Number(firstPrioritiesRes[0]); + } + + return secondPrioritiesCalc(firstPrioritiesRes); +}; diff --git a/src/lesson2/index.ts b/src/lesson2/index.ts new file mode 100644 index 0000000..b162399 --- /dev/null +++ b/src/lesson2/index.ts @@ -0,0 +1,30 @@ +import { createInterface } from 'readline'; + +import { calc } from './calc'; + +const rl = createInterface({ + input: process.stdin, + output: process.stdout, +}); + +const question = (): Promise => + new Promise((resolve) => { + rl.question('> ', (answer: string) => { + const result = calc(answer); + + if (result) { + // eslint-disable-next-line no-console + console.log(`Result: ${result}`); + } + + resolve(); + }); + }); + +async function app(): Promise { + while (true) { + await question(); + } +} + +app(); diff --git a/src/lesson2/logic.test.ts b/src/lesson2/logic.test.ts new file mode 100644 index 0000000..9fc133a --- /dev/null +++ b/src/lesson2/logic.test.ts @@ -0,0 +1,15 @@ +import { degreeСalc, firstPrioritiesCalc, secondPrioritiesCalc } from './logic'; + +describe('Positive test case', () => { + it('degree 11** + 3', () => { + expect(degreeСalc([11, '**', '+', 3])).toEqual([121, '+', 3]); + }); + + it('firstPrioritiesCalc 4 * 5 + 6', () => { + expect(firstPrioritiesCalc([4, '*', 5, '+', 6])).toEqual([20, '+', 6]); + }); + + it('secondPrioritiesCalc 4 + 5 + 6', () => { + expect(secondPrioritiesCalc([4, '+', 5, '+', 6])).toEqual(15); + }); +}); diff --git a/src/lesson2/logic.ts b/src/lesson2/logic.ts new file mode 100644 index 0000000..318f1af --- /dev/null +++ b/src/lesson2/logic.ts @@ -0,0 +1,46 @@ +import { operators, operatorsPriorities, priorites } from './operators'; + +type outValue = (string | number)[]; + +const [FIRST, SECOND] = priorites; + +export const degreeСalc = (extention: outValue): outValue => + extention.reduce((result, item) => { + const operandLeft = result[result.length - 1]; + + if (item === '**') { + result = [ + ...result.slice(0, -1), + operators[item](Number(operandLeft), Number(operandLeft)), + ]; + } else { + result.push(item); + } + return result; + }, []); + +export const firstPrioritiesCalc = (extention: outValue): outValue => + extention.reduce((arr, operandRight) => { + const operandLeft = arr[arr.length - 2]; + const operand = arr[arr.length - 1]; + + if (operatorsPriorities[operand] === FIRST) { + arr = [ + ...arr.slice(0, -2), + operators[operand](Number(operandLeft), Number(operandRight)), + ]; + } else { + arr.push(operandRight); + } + return arr; + }, []); + +export const secondPrioritiesCalc = (extention: outValue): number => + extention.reduce((result, nextItem, key) => { + const operand = extention[key - 1]; + + if (operatorsPriorities[operand] === SECOND) { + result = operators[operand](Number(result), Number(nextItem)); + } + return result; + }, Number(extention[0])); diff --git a/src/lesson2/operators.test.ts b/src/lesson2/operators.test.ts new file mode 100644 index 0000000..1916a4a --- /dev/null +++ b/src/lesson2/operators.test.ts @@ -0,0 +1,37 @@ +import { division, multiplication, addition, subtraction } from './operators'; + +describe('Positive test case', () => { + it('multiplication 2 * 2 = 4', () => { + expect(multiplication(2, 2)).toBe(4); + }); + + it('division 8 / 2 = 4', () => { + expect(division(8, 2)).toBe(4); + }); + + it('addition 5 + 2 = 7', () => { + expect(addition(5, 2)).toBe(7); + }); + + it('subtraction 5 - 2 = 3', () => { + expect(subtraction(5, 2)).toBe(3); + }); +}); + +describe('Negative test case', () => { + it('multiplication 2 * 2 != 6', () => { + expect(multiplication(2, 2)).not.toBe(6); + }); + + it('division 8 / 2 != 2', () => { + expect(division(8, 2)).not.toBe(5); + }); + + it('addition 5 + 2 != 8', () => { + expect(addition(5, 2)).not.toBe(8); + }); + + it('subtraction 5 - 8 != 3', () => { + expect(subtraction(5, 8)).not.toBe(4); + }); +}); diff --git a/src/lesson2/operators.ts b/src/lesson2/operators.ts new file mode 100644 index 0000000..c7f1920 --- /dev/null +++ b/src/lesson2/operators.ts @@ -0,0 +1,45 @@ +type typeOperators = (first: number, second: number) => number; + +export const addition: typeOperators = ( + first: number, + second: number, +): number => first + second; + +export const subtraction: typeOperators = ( + first: number, + second: number, +): number => first - second; + +export const multiplication: typeOperators = ( + first: number, + second: number, +): number => first * second; + +export const division: typeOperators = ( + first: number, + second: number, +): number => first / second; + +export const power: typeOperators = (first: number): number => (first *= first); + +export const operators: { + [key: string]: typeOperators; +} = { + '/': division, + '*': multiplication, + '+': addition, + '-': subtraction, + '**': power, +}; + +export const priorites = [1, 2]; + +const [FIRST, SECOND] = priorites; + +export const operatorsPriorities: { [key: string]: number } = { + '*': FIRST, + '/': FIRST, + '**': FIRST, + '+': SECOND, + '-': SECOND, +}; diff --git a/src/lesson2/parser.test.ts b/src/lesson2/parser.test.ts new file mode 100644 index 0000000..e1c8731 --- /dev/null +++ b/src/lesson2/parser.test.ts @@ -0,0 +1,37 @@ +import { parser } from './parser'; + +describe('Parser correct cases', () => { + it('2 + 2', () => { + expect(parser('2 + 2')).toEqual([2, '+', 2]); + }); + + it('2 + 2 + 5 + 7', () => { + expect(parser('2 + 2 + 5 + 7')).toEqual([2, '+', 2, '+', 5, '+', 7]); + }); + + it('11 + 3 * 22', () => { + expect(parser('11 + 3 * 22')).toEqual([11, '+', 3, '*', 22]); + }); + + it('11** + 3 * 22', () => { + expect(parser('11** + 3 * 22')).toEqual([11, '**', '+', 3, '*', 22]); + }); + + it('2** + 2 + 2', () => { + expect(parser('2** + 2 + 2')).toEqual([2, '**', '+', 2, '+', 2]); + }); +}); + +describe('Parser invalid cases', () => { + it('1 + + 33 - 2', () => { + expect(() => parser('1 + + 33 - 2')).toThrow( + TypeError('Unexpected string'), + ); + }); + + it('1 ! 33 - 2', () => { + expect(() => parser('1 ! 33 - 2')).toThrow( + TypeError('Unexpected string'), + ); + }); +}); diff --git a/src/lesson2/parser.ts b/src/lesson2/parser.ts new file mode 100644 index 0000000..67b1a64 --- /dev/null +++ b/src/lesson2/parser.ts @@ -0,0 +1,21 @@ +export const parser = (extention: string): (string | number)[] => { + const parserExtention = extention.split(' '); + + return parserExtention.reduce<(number | string)[]>((arr, item, key) => { + if (item.match(/\d*\*\*$/)) { + arr.push(Number(item.replace(/\*\*/, ''))); + arr.push(String(item.replace(/\d*/, ''))); + } else if (item.match(/^-{0,1}\d+$/)) { + arr.push(Number(item)); + } else if ( + ['-', '+', '/', '*'].includes(item) && + arr.indexOf(item, arr.length - 1) == -1 + ) { + arr.push(item); + } else { + throw new TypeError('Unexpected string'); + } + + return arr; + }, []); +}; From 5ccada26ff1dcb887d45aa5f2bcdc36860b1782b Mon Sep 17 00:00:00 2001 From: Maxim Kremnev Date: Thu, 30 Jul 2020 15:19:08 +0300 Subject: [PATCH 2/2] Added powerto, factorial --- src/lesson2/calc.test.ts | 16 ++++---- src/lesson2/calc.ts | 7 ++-- src/lesson2/common.ts | 9 +++++ src/lesson2/logic.test.ts | 42 ++++++++++++++------ src/lesson2/logic.ts | 15 ++++--- src/lesson2/operators.test.ts | 73 ++++++++++++++++++----------------- src/lesson2/operators.ts | 26 ++++++++++++- src/lesson2/parser.test.ts | 58 ++++++++++++---------------- src/lesson2/parser.ts | 25 +++++++++--- tsconfig.json | 4 +- 10 files changed, 168 insertions(+), 107 deletions(-) create mode 100644 src/lesson2/common.ts diff --git a/src/lesson2/calc.test.ts b/src/lesson2/calc.test.ts index 9682c2d..cbaecf0 100644 --- a/src/lesson2/calc.test.ts +++ b/src/lesson2/calc.test.ts @@ -1,11 +1,11 @@ import { calc } from './calc'; -describe('Positve test case', () => { - it('Extentions 2 + 2 + 2 = 6', () => { - expect(calc('2 + 2 + 2')).toBe(6); - }); - - it('Extentions 2** + 2 + 2 = 8', () => { - expect(calc('2** + 2 + 2')).toBe(8); - }); +test.each` + input | expected + ${'2 + 2 + 2'} | ${6} + ${'2** + 2 + 2'} | ${8} + ${'4! + 2 + 2'} | ${28} + ${'4^2 + 2 + 2'} | ${20} +`('receive $expected submit functions calc($input)', ({ input, expected }) => { + expect(calc(input)).toEqual(expected); }); diff --git a/src/lesson2/calc.ts b/src/lesson2/calc.ts index da14f76..413086a 100644 --- a/src/lesson2/calc.ts +++ b/src/lesson2/calc.ts @@ -5,9 +5,10 @@ import { firstPrioritiesCalc, secondPrioritiesCalc, degreeСalc } from './logic' export const calc = (extention: string): number => { const parserExtention = parser(extention); - const firstPrioritiesRes = parserExtention.includes('**') - ? degreeСalc(parserExtention) - : firstPrioritiesCalc(parserExtention); + const firstPrioritiesRes = + parserExtention.includes('**') || parserExtention.includes('!') + ? degreeСalc(parserExtention) + : firstPrioritiesCalc(parserExtention); if (firstPrioritiesRes.length === 1) { return Number(firstPrioritiesRes[0]); diff --git a/src/lesson2/common.ts b/src/lesson2/common.ts new file mode 100644 index 0000000..e7d73b8 --- /dev/null +++ b/src/lesson2/common.ts @@ -0,0 +1,9 @@ +export type parserType = (string | number)[]; + +export function isNumeric(params: string | number): boolean { + if (!isNaN(Number(params))) { + return true; + } else { + return false; + } +} diff --git a/src/lesson2/logic.test.ts b/src/lesson2/logic.test.ts index 9fc133a..ddb4559 100644 --- a/src/lesson2/logic.test.ts +++ b/src/lesson2/logic.test.ts @@ -1,15 +1,35 @@ import { degreeСalc, firstPrioritiesCalc, secondPrioritiesCalc } from './logic'; -describe('Positive test case', () => { - it('degree 11** + 3', () => { - expect(degreeСalc([11, '**', '+', 3])).toEqual([121, '+', 3]); - }); +test.each` + input | expected + ${[11, '**', '+', 3]} | ${[121, '+', 3]} + ${[4, '!', '+', 3]} | ${[24, '+', 3]} +`( + 'receive $expected submit functions degreeСalc($input)', + ({ input, expected }) => { + expect(degreeСalc(input)).toEqual(expected); + }, +); - it('firstPrioritiesCalc 4 * 5 + 6', () => { - expect(firstPrioritiesCalc([4, '*', 5, '+', 6])).toEqual([20, '+', 6]); - }); +test.each` + input | expected + ${[4, '^', 2, '+', 6]} | ${[16, '+', 6]} + ${[4, '*', 5, '+', 6]} | ${[20, '+', 6]} +`( + 'receive $expected submit functions firstPrioritiesCalc($input)', + ({ input, expected }) => { + expect(firstPrioritiesCalc(input)).toEqual(expected); + }, +); - it('secondPrioritiesCalc 4 + 5 + 6', () => { - expect(secondPrioritiesCalc([4, '+', 5, '+', 6])).toEqual(15); - }); -}); +test.each` + input | expected + ${[4, '+', 5, '+', 6]} | ${15} + ${[9, '+', 1, '+', 10]} | ${20} + ${[9, '+', 1, '-', 5]} | ${5} +`( + 'receive $expected submit functions secondPrioritiesCalc($input)', + ({ input, expected }) => { + expect(secondPrioritiesCalc(input)).toBe(expected); + }, +); diff --git a/src/lesson2/logic.ts b/src/lesson2/logic.ts index 318f1af..cbe0a7f 100644 --- a/src/lesson2/logic.ts +++ b/src/lesson2/logic.ts @@ -1,14 +1,13 @@ import { operators, operatorsPriorities, priorites } from './operators'; - -type outValue = (string | number)[]; +import { parserType } from './common'; const [FIRST, SECOND] = priorites; -export const degreeСalc = (extention: outValue): outValue => - extention.reduce((result, item) => { +export const degreeСalc = (extention: parserType): parserType => + extention.reduce((result, item, key, arr) => { const operandLeft = result[result.length - 1]; - if (item === '**') { + if (item === '**' || item === '!') { result = [ ...result.slice(0, -1), operators[item](Number(operandLeft), Number(operandLeft)), @@ -19,8 +18,8 @@ export const degreeСalc = (extention: outValue): outValue => return result; }, []); -export const firstPrioritiesCalc = (extention: outValue): outValue => - extention.reduce((arr, operandRight) => { +export const firstPrioritiesCalc = (extention: parserType): parserType => + extention.reduce((arr, operandRight) => { const operandLeft = arr[arr.length - 2]; const operand = arr[arr.length - 1]; @@ -35,7 +34,7 @@ export const firstPrioritiesCalc = (extention: outValue): outValue => return arr; }, []); -export const secondPrioritiesCalc = (extention: outValue): number => +export const secondPrioritiesCalc = (extention: parserType): number => extention.reduce((result, nextItem, key) => { const operand = extention[key - 1]; diff --git a/src/lesson2/operators.test.ts b/src/lesson2/operators.test.ts index 1916a4a..b5982b8 100644 --- a/src/lesson2/operators.test.ts +++ b/src/lesson2/operators.test.ts @@ -1,37 +1,40 @@ -import { division, multiplication, addition, subtraction } from './operators'; - -describe('Positive test case', () => { - it('multiplication 2 * 2 = 4', () => { - expect(multiplication(2, 2)).toBe(4); - }); - - it('division 8 / 2 = 4', () => { - expect(division(8, 2)).toBe(4); - }); - - it('addition 5 + 2 = 7', () => { - expect(addition(5, 2)).toBe(7); - }); - - it('subtraction 5 - 2 = 3', () => { - expect(subtraction(5, 2)).toBe(3); - }); +import { + division, + multiplication, + addition, + subtraction, + power, + powerto, + factorial, +} from './operators'; + +test.each` + input | expected | textinput + ${multiplication(2, 2)} | ${4} | ${'multiplication(2, 2)'} + ${division(8, 2)} | ${4} | ${'division(8, 2)'} + ${addition(5, 2)} | ${7} | ${'addition(5, 2)'} + ${subtraction(5, 2)} | ${3} | ${'subtraction(5, 2)'} + ${power(5)} | ${25} | ${'power(5)'} + ${powerto(5, 3)} | ${125} | ${'powerto(5, 3)'} + ${factorial(5)} | ${120} | ${'factorial(5)'} + ${factorial(1)} | ${1} | ${'factorial(1)'} +`('receive $expected submit functions $textinput', ({ input, expected }) => { + expect(input).toBe(expected); }); -describe('Negative test case', () => { - it('multiplication 2 * 2 != 6', () => { - expect(multiplication(2, 2)).not.toBe(6); - }); - - it('division 8 / 2 != 2', () => { - expect(division(8, 2)).not.toBe(5); - }); - - it('addition 5 + 2 != 8', () => { - expect(addition(5, 2)).not.toBe(8); - }); - - it('subtraction 5 - 8 != 3', () => { - expect(subtraction(5, 8)).not.toBe(4); - }); -}); +test.each` + input | expected | textinput + ${multiplication(2, 2)} | ${6} | ${'multiplication(2, 2)'} + ${division(8, 2)} | ${5} | ${'division(8, 2)'} + ${addition(5, 2)} | ${8} | ${'addition(5, 2)'} + ${subtraction(5, 2)} | ${4} | ${'subtraction(5, 2)'} + ${power(5)} | ${24} | ${'power(5)'} + ${powerto(5, 3)} | ${123} | ${'powerto(5, 3)'} + ${factorial(5)} | ${121} | ${'factorial(5)'} + ${factorial(1)} | ${2} | ${'factorial(1)'} +`( + 'receive shouldn`t be $expected submit functions $textinput', + ({ input, expected }) => { + expect(input).not.toBe(expected); + }, +); diff --git a/src/lesson2/operators.ts b/src/lesson2/operators.ts index c7f1920..cb66412 100644 --- a/src/lesson2/operators.ts +++ b/src/lesson2/operators.ts @@ -1,4 +1,5 @@ type typeOperators = (first: number, second: number) => number; +type oneParametrsType = (value: number) => number; export const addition: typeOperators = ( first: number, @@ -20,7 +21,26 @@ export const division: typeOperators = ( second: number, ): number => first / second; -export const power: typeOperators = (first: number): number => (first *= first); +export const power: oneParametrsType = (first: number): number => + (first *= first); + +export const powerto: typeOperators = ( + first: number, + second: number, +): number => { + let result = first; + for (let pow = 1; pow < second; pow++) { + result *= first; + } + return result; +}; + +export const factorial: oneParametrsType = (value: number): number => { + if (value === 1) { + return 1; + } + return value * factorial(value - 1); +}; export const operators: { [key: string]: typeOperators; @@ -30,6 +50,8 @@ export const operators: { '+': addition, '-': subtraction, '**': power, + '^': powerto, + '!': factorial, }; export const priorites = [1, 2]; @@ -37,9 +59,11 @@ export const priorites = [1, 2]; const [FIRST, SECOND] = priorites; export const operatorsPriorities: { [key: string]: number } = { + '!': FIRST, '*': FIRST, '/': FIRST, '**': FIRST, + '^': FIRST, '+': SECOND, '-': SECOND, }; diff --git a/src/lesson2/parser.test.ts b/src/lesson2/parser.test.ts index e1c8731..cb04fa9 100644 --- a/src/lesson2/parser.test.ts +++ b/src/lesson2/parser.test.ts @@ -1,37 +1,27 @@ import { parser } from './parser'; -describe('Parser correct cases', () => { - it('2 + 2', () => { - expect(parser('2 + 2')).toEqual([2, '+', 2]); - }); +test.each` + input | expected + ${'1 + + 33 - 2'} | ${'Unexpected string'} + ${'1 ! 33 - 2'} | ${'Unexpected string'} +`( + 'receive $expected after parsing the string $input', + ({ input, expected }) => { + expect(() => parser(input)).toThrow(TypeError(expected)); + }, +); - it('2 + 2 + 5 + 7', () => { - expect(parser('2 + 2 + 5 + 7')).toEqual([2, '+', 2, '+', 5, '+', 7]); - }); - - it('11 + 3 * 22', () => { - expect(parser('11 + 3 * 22')).toEqual([11, '+', 3, '*', 22]); - }); - - it('11** + 3 * 22', () => { - expect(parser('11** + 3 * 22')).toEqual([11, '**', '+', 3, '*', 22]); - }); - - it('2** + 2 + 2', () => { - expect(parser('2** + 2 + 2')).toEqual([2, '**', '+', 2, '+', 2]); - }); -}); - -describe('Parser invalid cases', () => { - it('1 + + 33 - 2', () => { - expect(() => parser('1 + + 33 - 2')).toThrow( - TypeError('Unexpected string'), - ); - }); - - it('1 ! 33 - 2', () => { - expect(() => parser('1 ! 33 - 2')).toThrow( - TypeError('Unexpected string'), - ); - }); -}); +test.each` + input | expected + ${'2 + 2'} | ${[2, '+', 2]} + ${'2 + 2 + 5 + 7'} | ${[2, '+', 2, '+', 5, '+', 7]} + ${'11 + 3 * 22'} | ${[11, '+', 3, '*', 22]} + ${'11** + 3 * 22'} | ${[11, '**', '+', 3, '*', 22]} + ${'2** + 2 + 2'} | ${[2, '**', '+', 2, '+', 2]} + ${'2** + 2 + 2 + 2!'} | ${[2, '**', '+', 2, '+', 2, '+', 2, '!']} +`( + 'receive $expected after parsing the string $input', + ({ input, expected }) => { + expect(parser(input)).toEqual(expected); + }, +); diff --git a/src/lesson2/parser.ts b/src/lesson2/parser.ts index 67b1a64..574cfa1 100644 --- a/src/lesson2/parser.ts +++ b/src/lesson2/parser.ts @@ -1,10 +1,25 @@ -export const parser = (extention: string): (string | number)[] => { +import { parserType, isNumeric } from './common'; +export const parser = (extention: string): parserType => { const parserExtention = extention.split(' '); - return parserExtention.reduce<(number | string)[]>((arr, item, key) => { - if (item.match(/\d*\*\*$/)) { - arr.push(Number(item.replace(/\*\*/, ''))); - arr.push(String(item.replace(/\d*/, ''))); + return parserExtention.reduce((arr, item) => { + if ( + item.match(/((\d+)(\*\*))?((\d+)(\!))?((\d+)(\^)(\d*))?$/)![0] + .length > 1 + ) { + item.match(/((\d+)(\*\*))?((\d+)(\!))?((\d+)(\^)(\d+))?$/)! + .filter((value) => { + return ( + value != undefined && + !value.match(/\d+(\!|\^|\*\*)(\d*)?$/) + ); + }) + .forEach((value) => { + const typeValue = isNumeric(value) + ? Number(value) + : String(value); + arr.push(typeValue); + }); } else if (item.match(/^-{0,1}\d+$/)) { arr.push(Number(item)); } else if ( diff --git a/tsconfig.json b/tsconfig.json index 67700ae..cbfdacb 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,8 +7,8 @@ "target": "ES2017" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */, "module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */, // "lib": [], /* Specify library files to be included in the compilation. */ - "allowJs": true, /* Allow javascript files to be compiled. */ - "checkJs": true, /* Report errors in .js files. */ + "allowJs": true /* Allow javascript files to be compiled. */, + "checkJs": true /* Report errors in .js files. */, // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ // "declaration": true, /* Generates corresponding '.d.ts' file. */ // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */