🧙♂️
Mystic Sage
world hello
1
Convert to Array
2
Reverse Entire String
3
Reverse Each Word
Portal Locked
📜 Decoded Message
-
📋 Animation Log
Click "Decode Message" to see the algorithm in action
Level 1
"world hello"
Level 2
"blue is sky the"
Level 3
"fun is coding"
Level 4
"rocks algorithms string"
💡 Algorithm: Reverse Sentence Word by Word
function reverseSentenceWordByWord(sentence) { // Step 1: Convert
string to character array let chars = sentence.split(''); // Step 2:
Reverse the entire string reverse(chars, 0, chars.length - 1); // Step
3: Reverse each word individually let start = 0; for (let i = 0; i <=
chars.length; i++) { // When we hit a space or end, reverse the word
if (i === chars.length || chars[i] === ' ') { reverse(chars, start, i
- 1); start = i + 1; } } return chars.join(''); } function
reverse(chars, left, right) { while (left < right) { // Swap
characters let temp = chars[left]; chars[left] = chars[right];
chars[right] = temp; left++; right--; } }