Refactor replaceOperators function to use chain methods

This commit is contained in:
martin 2023-07-24 22:21:43 +02:00
parent 449673800d
commit de8305e797

View File

@ -4,13 +4,11 @@
* @returns The expression with the replaced operators * @returns The expression with the replaced operators
*/ */
export function replaceOperators(expression: string): string { export function replaceOperators(expression: string): string {
return expression
expression = expression.replaceAll(/\//g, "|"); .replaceAll(/\//g, "|")
expression = expression.replaceAll(/¬/g, "!"); .replaceAll(/¬/g, "!")
expression = expression.replaceAll(/\sOR\s/gi, " | "); .replaceAll(/\sOR\s/gi, " | ")
expression = expression.replaceAll(/\sAND\s/gi, " & "); .replaceAll(/\sAND\s/gi, " & ")
expression = expression.replaceAll(/\s(IMPLICATION|IMP)\s/gi, " -> "); .replaceAll(/\s(IMPLICATION|IMP)\s/gi, " -> ")
expression = expression.replaceAll(/\sNOT\s/gi, " !"); .replaceAll(/\sNOT\s/gi, " !");
}
return expression;
}