DEV Community

Justin
Justin

Posted on

JS Challenge: Reverse the characters of each word in a string

The solution is to create an array of the characters in the string by using the split() function, reverse the array and then join the characters back into a string using join() function.

str = 'Once upon a time there was clean fresh air';
str.split(' ').map(word => 
  word.split('').reverse().join('')
).join(' ');

//To reverse the order of words in the string too

str.split(' ').map(word => 
  word.split('').reverse().join('')
).reverse().join(' ');

Enter fullscreen mode Exit fullscreen mode

Top comments (0)

ACI image

ACI.dev: Fully Open-source AI Agent Tool-Use Infra (Composio Alternative)

100% open-source tool-use platform (backend, dev portal, integration library, SDK/MCP) that connects your AI agents to 600+ tools with multi-tenant auth, granular permissions, and access through direct function calling or a unified MCP server.

Check out our GitHub!

Join the Runner H "AI Agent Prompting" Challenge: $10,000 in Prizes for 20 Winners!

Runner H is the AI agent you can delegate all your boring and repetitive tasks to - an autonomous agent that can use any tools you give it and complete full tasks from a single prompt.

Check out the challenge

DEV is bringing live events to the community. Dismiss if you're not interested. ❤️