From b156fc99298a328e4410a64c616b2f02f9158b5c Mon Sep 17 00:00:00 2001 From: sw5678 <151949597+sw5678@users.noreply.github.com> Date: Mon, 12 May 2025 11:14:23 +0100 Subject: [PATCH] Fixed bug where spaces were causing the text to not be correct --- src/core/operations/AlternatingCaps.mjs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/core/operations/AlternatingCaps.mjs b/src/core/operations/AlternatingCaps.mjs index 17ce3fed..bcdf9523 100644 --- a/src/core/operations/AlternatingCaps.mjs +++ b/src/core/operations/AlternatingCaps.mjs @@ -33,11 +33,18 @@ class AlternatingCaps extends Operation { */ run(input, args) { let output = ""; + let previousCaps = true; for (let i = 0; i < input.length; i++) { - if (i % 2 === 0) { + // Check if the element is a letter + if (!RegExp(/^\p{L}/,'u').test(input[i])) { + output += input[i]; + } + else if (previousCaps) { output += input[i].toLowerCase(); + previousCaps = false; } else { output += input[i].toUpperCase(); + previousCaps = true; } } return output;