From af781621bd373a156ef695c1cbe48895ad11c44b Mon Sep 17 00:00:00 2001 From: Leonabcd123 <156839416+Leonabcd123@users.noreply.github.com> Date: Mon, 17 Aug 2026 08:49:53 +0300 Subject: [PATCH 01/11] Literally magic --- frontend/src/ts/test/funbox/funbox-functions.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frontend/src/ts/test/funbox/funbox-functions.ts b/frontend/src/ts/test/funbox/funbox-functions.ts index 7430c0b6bae6..8e1f47c2307f 100644 --- a/frontend/src/ts/test/funbox/funbox-functions.ts +++ b/frontend/src/ts/test/funbox/funbox-functions.ts @@ -348,7 +348,9 @@ const list: Partial> = { }, backwards: { alterText(word: string): string { - return word.split("").reverse().join(""); + // @ts-expect-error - v flag is only supported in es2024+, need to consider alternatives + const regex = /\p{RGI_Emoji}|\p{Any}/gv; + return (word.match(regex) ?? []).reverse().join(""); }, }, capitals: { From 9bd0ebff877aa6f39d356fc3cf2a096eff772f24 Mon Sep 17 00:00:00 2001 From: Leonabcd123 <156839416+Leonabcd123@users.noreply.github.com> Date: Mon, 17 Aug 2026 10:22:03 +0300 Subject: [PATCH 02/11] Another approach --- .../src/ts/test/funbox/funbox-functions.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/frontend/src/ts/test/funbox/funbox-functions.ts b/frontend/src/ts/test/funbox/funbox-functions.ts index 8e1f47c2307f..e5174cf36ed5 100644 --- a/frontend/src/ts/test/funbox/funbox-functions.ts +++ b/frontend/src/ts/test/funbox/funbox-functions.ts @@ -348,9 +348,22 @@ const list: Partial> = { }, backwards: { alterText(word: string): string { - // @ts-expect-error - v flag is only supported in es2024+, need to consider alternatives - const regex = /\p{RGI_Emoji}|\p{Any}/gv; - return (word.match(regex) ?? []).reverse().join(""); + const segmenter = new Intl.Segmenter(); + const graphemes = [...segmenter.segment(word)].map((s) => s.segment); + + const emojiComponentRegex = /\p{Emoji_Component}/u; + + const units = []; + for (const g of graphemes) { + // Handles emojis that have ZWJs and regional indicators + if (emojiComponentRegex.test(g)) { + units.push(g); + continue; + } + + units.push(...g); + } + return units.reverse().join(""); }, }, capitals: { From 18d9db2eb09003eb804685887690cd6667b4f354 Mon Sep 17 00:00:00 2001 From: Leonabcd123 <156839416+Leonabcd123@users.noreply.github.com> Date: Mon, 17 Aug 2026 13:13:47 +0300 Subject: [PATCH 03/11] Improve --- frontend/src/ts/test/funbox/funbox-functions.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontend/src/ts/test/funbox/funbox-functions.ts b/frontend/src/ts/test/funbox/funbox-functions.ts index e5174cf36ed5..81385f7206c5 100644 --- a/frontend/src/ts/test/funbox/funbox-functions.ts +++ b/frontend/src/ts/test/funbox/funbox-functions.ts @@ -351,12 +351,13 @@ const list: Partial> = { const segmenter = new Intl.Segmenter(); const graphemes = [...segmenter.segment(word)].map((s) => s.segment); + const emojiRegex = /\p{Emoji}/u; const emojiComponentRegex = /\p{Emoji_Component}/u; const units = []; for (const g of graphemes) { // Handles emojis that have ZWJs and regional indicators - if (emojiComponentRegex.test(g)) { + if (emojiRegex.test(g) && emojiComponentRegex.test(g)) { units.push(g); continue; } From 1261307da20aea3f866920c16a649be9e320efe0 Mon Sep 17 00:00:00 2001 From: Leonabcd123 <156839416+Leonabcd123@users.noreply.github.com> Date: Mon, 17 Aug 2026 13:33:38 +0300 Subject: [PATCH 04/11] Remove --- frontend/src/ts/test/funbox/funbox-functions.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/frontend/src/ts/test/funbox/funbox-functions.ts b/frontend/src/ts/test/funbox/funbox-functions.ts index 81385f7206c5..f3336a946119 100644 --- a/frontend/src/ts/test/funbox/funbox-functions.ts +++ b/frontend/src/ts/test/funbox/funbox-functions.ts @@ -352,12 +352,10 @@ const list: Partial> = { const graphemes = [...segmenter.segment(word)].map((s) => s.segment); const emojiRegex = /\p{Emoji}/u; - const emojiComponentRegex = /\p{Emoji_Component}/u; const units = []; for (const g of graphemes) { - // Handles emojis that have ZWJs and regional indicators - if (emojiRegex.test(g) && emojiComponentRegex.test(g)) { + if (emojiRegex.test(g)) { units.push(g); continue; } From 94a32d06d2d3e41b075db29aea4024ad87a6d207 Mon Sep 17 00:00:00 2001 From: Leonabcd123 <156839416+Leonabcd123@users.noreply.github.com> Date: Mon, 17 Aug 2026 13:35:08 +0300 Subject: [PATCH 05/11] Refactor --- frontend/src/ts/test/funbox/funbox-functions.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/frontend/src/ts/test/funbox/funbox-functions.ts b/frontend/src/ts/test/funbox/funbox-functions.ts index f3336a946119..346dcab240fc 100644 --- a/frontend/src/ts/test/funbox/funbox-functions.ts +++ b/frontend/src/ts/test/funbox/funbox-functions.ts @@ -357,10 +357,9 @@ const list: Partial> = { for (const g of graphemes) { if (emojiRegex.test(g)) { units.push(g); - continue; + } else { + units.push(...g); } - - units.push(...g); } return units.reverse().join(""); }, From a913ae90c4ea5fa490638fa262002ff5d5a501aa Mon Sep 17 00:00:00 2001 From: Leonabcd123 <156839416+Leonabcd123@users.noreply.github.com> Date: Mon, 17 Aug 2026 16:03:19 +0300 Subject: [PATCH 06/11] flatmap --- frontend/src/ts/test/funbox/funbox-functions.ts | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/frontend/src/ts/test/funbox/funbox-functions.ts b/frontend/src/ts/test/funbox/funbox-functions.ts index 346dcab240fc..b92b44847f98 100644 --- a/frontend/src/ts/test/funbox/funbox-functions.ts +++ b/frontend/src/ts/test/funbox/funbox-functions.ts @@ -350,17 +350,12 @@ const list: Partial> = { alterText(word: string): string { const segmenter = new Intl.Segmenter(); const graphemes = [...segmenter.segment(word)].map((s) => s.segment); - const emojiRegex = /\p{Emoji}/u; - const units = []; - for (const g of graphemes) { - if (emojiRegex.test(g)) { - units.push(g); - } else { - units.push(...g); - } - } + const units = graphemes.flatMap((g) => + emojiRegex.test(g) ? [g] : [...g], + ); + return units.reverse().join(""); }, }, From 0a882d6582d703040cc8d1f199d9f7aeb31743cd Mon Sep 17 00:00:00 2001 From: Leonabcd123 <156839416+Leonabcd123@users.noreply.github.com> Date: Mon, 17 Aug 2026 16:04:43 +0300 Subject: [PATCH 07/11] Add fallback --- frontend/src/ts/test/funbox/funbox-functions.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frontend/src/ts/test/funbox/funbox-functions.ts b/frontend/src/ts/test/funbox/funbox-functions.ts index b92b44847f98..dd50f89bdc86 100644 --- a/frontend/src/ts/test/funbox/funbox-functions.ts +++ b/frontend/src/ts/test/funbox/funbox-functions.ts @@ -348,6 +348,8 @@ const list: Partial> = { }, backwards: { alterText(word: string): string { + if (!("Segmenter" in Intl)) return [...word].reverse().join(""); + const segmenter = new Intl.Segmenter(); const graphemes = [...segmenter.segment(word)].map((s) => s.segment); const emojiRegex = /\p{Emoji}/u; From 043d64ce4f9f5fe9439f80cf7987422c490d4d6b Mon Sep 17 00:00:00 2001 From: Leonabcd123 <156839416+Leonabcd123@users.noreply.github.com> Date: Mon, 17 Aug 2026 16:27:08 +0300 Subject: [PATCH 08/11] Comment --- frontend/src/ts/test/funbox/funbox-functions.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frontend/src/ts/test/funbox/funbox-functions.ts b/frontend/src/ts/test/funbox/funbox-functions.ts index dd50f89bdc86..72b343ecb611 100644 --- a/frontend/src/ts/test/funbox/funbox-functions.ts +++ b/frontend/src/ts/test/funbox/funbox-functions.ts @@ -354,6 +354,8 @@ const list: Partial> = { const graphemes = [...segmenter.segment(word)].map((s) => s.segment); const emojiRegex = /\p{Emoji}/u; + // The codepoints making up an emoji aren't reversed, everything else is split + // and reversed. const units = graphemes.flatMap((g) => emojiRegex.test(g) ? [g] : [...g], ); From 9e3564df77059027e1ba08c7bc2e9e425aa79517 Mon Sep 17 00:00:00 2001 From: Leonabcd123 <156839416+Leonabcd123@users.noreply.github.com> Date: Mon, 17 Aug 2026 16:27:50 +0300 Subject: [PATCH 09/11] Sequence --- frontend/src/ts/test/funbox/funbox-functions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/ts/test/funbox/funbox-functions.ts b/frontend/src/ts/test/funbox/funbox-functions.ts index 72b343ecb611..738cf8d5b40d 100644 --- a/frontend/src/ts/test/funbox/funbox-functions.ts +++ b/frontend/src/ts/test/funbox/funbox-functions.ts @@ -354,7 +354,7 @@ const list: Partial> = { const graphemes = [...segmenter.segment(word)].map((s) => s.segment); const emojiRegex = /\p{Emoji}/u; - // The codepoints making up an emoji aren't reversed, everything else is split + // The codepoints making up an emoji sequence aren't reversed, everything else is split // and reversed. const units = graphemes.flatMap((g) => emojiRegex.test(g) ? [g] : [...g], From 9a6bc2d9fea0276da3cd4bc5e01dc1fef6af068b Mon Sep 17 00:00:00 2001 From: Leonabcd123 <156839416+Leonabcd123@users.noreply.github.com> Date: Mon, 17 Aug 2026 21:05:36 +0300 Subject: [PATCH 10/11] Comment --- frontend/src/ts/test/funbox/funbox-functions.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/frontend/src/ts/test/funbox/funbox-functions.ts b/frontend/src/ts/test/funbox/funbox-functions.ts index 738cf8d5b40d..c2fb7fbb11ce 100644 --- a/frontend/src/ts/test/funbox/funbox-functions.ts +++ b/frontend/src/ts/test/funbox/funbox-functions.ts @@ -354,8 +354,7 @@ const list: Partial> = { const graphemes = [...segmenter.segment(word)].map((s) => s.segment); const emojiRegex = /\p{Emoji}/u; - // The codepoints making up an emoji sequence aren't reversed, everything else is split - // and reversed. + // Emoji sequences aren't reversed, everything else is. const units = graphemes.flatMap((g) => emojiRegex.test(g) ? [g] : [...g], ); From 9a00809ce61616651de0f02caf1e168be1f74347 Mon Sep 17 00:00:00 2001 From: Leonabcd123 <156839416+Leonabcd123@users.noreply.github.com> Date: Mon, 17 Aug 2026 21:25:15 +0300 Subject: [PATCH 11/11] Comment --- frontend/src/ts/test/funbox/funbox-functions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/ts/test/funbox/funbox-functions.ts b/frontend/src/ts/test/funbox/funbox-functions.ts index c2fb7fbb11ce..161277d8c450 100644 --- a/frontend/src/ts/test/funbox/funbox-functions.ts +++ b/frontend/src/ts/test/funbox/funbox-functions.ts @@ -354,7 +354,7 @@ const list: Partial> = { const graphemes = [...segmenter.segment(word)].map((s) => s.segment); const emojiRegex = /\p{Emoji}/u; - // Emoji sequences aren't reversed, everything else is. + // Emojis aren't reversed, everything else is. const units = graphemes.flatMap((g) => emojiRegex.test(g) ? [g] : [...g], );