Learn Reverse Words in a String with a step-by-step Strings visualizer, JavaScript source code and a worked example. Practice fundamentals and parsing.
INTERACTIVE EXECUTION STUDIO
LEARN BY DOING
Predict. Execute. Understand.
Follow the source code, inspect live state changes, and predict the next operation before revealing it.
Follow the computed execution on the reference input. Advance one step at a time, inspect the changing values and compare your prediction with the final output.
Example input
" hello world "
Execution steps
Read word from right
Computed output
"world hello"
JavaScript reference implementation
const solve = (a,s)=>{
let words=a.trim().split(/\s+/),o=[];
for(let i=words.length-1;
i>=0;
i--){
o.push(words[i]);
s("Read word from right",{
Words:words,Output:o
},[i])
}
return o.join(" ")
};