Created
March 31, 2025 18:28
-
-
Save tcelestino/24933b6c1990d8fb83e41e7c3ac41264 to your computer and use it in GitHub Desktop.
Revisions
-
tcelestino created this gist
Mar 31, 2025 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ function manipulateText(text, command) { let cursor = 0; let result = text.split(''); for (let i = 0; i < command.length; i++) { const currentCommand = command[i]; if (currentCommand === 'h') { cursor = Math.max(0, cursor - 1); } else if (currentCommand === 'l') { cursor = Math.min(result.length - 1, cursor + 1); } else if (currentCommand === 'r' && i + 1 < command.length) { const newChar = command[i + 1]; result[cursor] = newChar; i++; } } return `${result.join('')} - cursor: ${cursor}`; }