From e57a33fff1c4478d2d643f76e0d8b0b8c8b3ddae Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Sun, 3 Dec 2023 10:39:14 +0200 Subject: [PATCH] Extract a common expression into a variable/const. This is Refactoring / code cleanup. See: * https://refactoring.com/catalog/extractMethod.html * https://en.wikipedia.org/wiki/Code_refactoring * https://www.refactoring.com/ * https://www.joelonsoftware.com/2002/01/23/rub-a-dub-dub/ Some small optimisations may have slipped in as well. --- .../wml/src/ts/web-fc-solve--expand-moves.ts | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/fc-solve/site/wml/src/ts/web-fc-solve--expand-moves.ts b/fc-solve/site/wml/src/ts/web-fc-solve--expand-moves.ts index 68387d20c..0528ce523 100644 --- a/fc-solve/site/wml/src/ts/web-fc-solve--expand-moves.ts +++ b/fc-solve/site/wml/src/ts/web-fc-solve--expand-moves.ts @@ -326,28 +326,29 @@ export function fc_solve_expand_moves_filter_solution_text( const board2move_sep = "\n\n====================\n\n"; const move2board_sep = "\n"; const move2board_sep4output = "\n\n"; + const re = new RegExp( + "(" + + board_pat + + ")" + + board2move_sep + + "(" + + move_line_pat + + ")" + + "\\n" + + move2board_sep + + "(?=" + + "(" + + board_pat + + ")" + + ")", + "gms", + ); let expanded_sol = initial_str; let changes = 0; do { changes = 0; expanded_sol = expanded_sol.replace( - new RegExp( - "(" + - board_pat + - ")" + - board2move_sep + - "(" + - move_line_pat + - ")" + - "\\n" + - move2board_sep + - "(?=" + - "(" + - board_pat + - ")" + - ")", - "gms", - ), + re, function replacer(match, initial_str, move, fin) { ++changes; let ret = "";