ProstDev ProstDev

DataWeave programming challenge #5: Reverse a phrase's words, but keep the punctuation

Thumbnail: DataWeave programming challenge #5: Reverse a phrase's words, but keep the punctuation
Watch on YouTube

About this video

Reverse the word order of each phrase in DataWeave while leaving punctuation marks fixed in their original positions. Clues and full solutions are in the companion article.

Resources

Transcript

Intro

Hi everyone, Alex here. I come here with DataWeave challenge number five for you. So in this case we are going to take a series of phrases, take each one of the words, and reverse them. So let me show you how we do that.

The challenge

In this case we have these five sentences or phrases — “hello world”, “May the force be with you”, and so on, in different presentations, so you can kind of test if they are all working perfectly. So each one of the lines is a phrase: “hello world”, “May the force be with you”, and then this one has an exclamation point, these two have commas, and then this one has an exclamation point at the end. So these are different tests that you can take to make sure that the reversal of the order is working.

But all of the punctuation signs have to stay in the same index, or in the same position. For example here, if we turn this around, this will be “world hello”, but the exclamation point will remain in this part. Same with this: if we reverse the order of the words we will have “force”, the comma, and then the rest of the string. And then here on this one, at the end, we will have the exclamation point.

Here you can see this is how all of the five phrases should look: “world hello” — notice that upper or lowercase on each of the words doesn’t really matter, we don’t have to do anything about it. “you with be force the May”, “world hello!”, and then both of these have “force,” (with the comma) and then “May”, “you with” and then exclamation point at the end on this one.

Wrap-up

So that’s all, that’s what you have to do for this challenge. It looks easy, but I really did spend a lot of time doing it, so I hope it’s way better for you. And please let me know what your solution was so I can take a look at it, because mine was long and I feel like there’s an easier way to do it — I just didn’t find out how exactly.

So that’s all. Remember to go to ProstDev.com/blog to find the article, or if you’re watching this from YouTube, go into the description of the video and you’ll see the link to this article so you can post your solution and see others’ solutions as well. Remember to subscribe to the YouTube channel ProstDev, or at ProstDev.com subscribe to receive notifications as soon as new articles come out. That’s it, good luck!

More from DataWeave Challenges

Search

Loading search…