An Interest In:
Web News this Week
- April 2, 2024
- April 1, 2024
- March 31, 2024
- March 30, 2024
- March 29, 2024
- March 28, 2024
- March 27, 2024
January 26, 2022 03:40 pm GMT
Original Link: https://dev.to/martinkr/1-line-of-code-how-to-reverse-all-words-of-a-string-n26
1 line of code: How to reverse all words of a string
const reverseWords = (str) => str.split(" ").map((word) => [...word].reverse().join("")).join(" ");
Returns the string with all words reversed
The repository & npm package
You can find the all the utility functions from this series at github.com/martinkr/onelinecode
The library is also published to npm as @onelinecode for your convenience.
The code and the npm package will be updated every time I publish a new article.
Follow me on Twitter: @martinkr and consider to buy me a coffee
Photo by zoo_monkey on Unsplash
Original Link: https://dev.to/martinkr/1-line-of-code-how-to-reverse-all-words-of-a-string-n26
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To