top of page

DataWeave programming challenge #3: Count palindrome phrases using the Strings module



 

Other posts from this series:

 

In this post:

 


Try to solve this challenge on your own to maximize learning. We recommend you refer to the DataWeave documentation only. Try to avoid using Google or asking others so you can learn on your own and become a DataWeave expert!


💡 Tip: For this challenge, we encourage you to make use of the Strings module's functions.



Input


Consider the following input payload (can be of txt format):


this is not a palindrome
blue
Mr. Owl ate my metal worm
Was it a car or a cat I saw?
you're doing great!
mug
Rats live on no evil star
what's taking so long?
kayak
Live on time, emit no evil
Step on no pets
boat
Anna
2020/02/02
15/03/2001
01/02/2010


Explanation of the problem


Each line of the input payload is considered a different phrase. Review each phrase and find those that are palindromes. Notice that punctuation, spaces, or special characters should not be considered to ensure a phrase is a palindrome.


For example,

  • Anna in reverse is anna - this is a palindrome.

  • 2020/02/02 in reverse is 20200202 - this is a palindrome.

  • Mr. Owl ate my metal worm in reverse is mrowlatemymetalworm - this is a palindrome.


After that, retrieve the character count of the original phrase. Including punctuation, spaces, and special characters.


For example,

  • Anna is 4.

  • 2020/02/02 is 10.

  • Mr. Owl ate my metal worm is 25.


Return the total sum of all the palindrome's character count.



Expected output


In this case, the expected output would be:


148

The result for each of the phrases (whether they're palindrome or not) should be:

  1. false

  2. false

  3. true

  4. true

  5. false

  6. false

  7. true

  8. false

  9. true

  10. true

  11. true

  12. false

  13. true

  14. true

  15. false

  16. true




Clues


If you're stuck with your solution, feel free to check out some of these clues to give you ideas on how to solve it!


Clue #1

Clue #2

Clue #3

Clue #4

Clue #5

Clue #6

Clue #7



Answer


If you haven't solved this challenge yet, we encourage you to keep trying! It's ok if it's taking longer than you thought. We all have to start somewhere ✨ Check out the clues and read the docs before giving up. You got this!! 💙


There are many ways to solve this challenge, but you can find here one of our solutions so you can compare your result with us.


Solution #1



Feel free to comment your code below for others to see! 😄


Subscribe to receive notifications as soon as new content is published ✨








583 views27 comments
bottom of page