DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • DataWeave Interview Question: Concatenate Elements of an Array
  • Top 10 Algorithms for the Coding Interview (for Software Engineers)
  • Reversing an Array: An Exploration of Array Manipulation
  • Unlocking the Potential of Binary Search Trees with C# Programming

Trending

  • Can You Run a MariaDB Cluster on a $150 Kubernetes Lab? I Gave It a Shot
  • AI Speaks for the World... But Whose Humanity Does It Learn From?
  • Introducing Graph Concepts in Java With Eclipse JNoSQL
  • Enhancing Business Decision-Making Through Advanced Data Visualization Techniques
  1. DZone
  2. Culture and Methodologies
  3. Career Development
  4. DataWeave Interview Question: Reverse an Array After Combining Its Elements

DataWeave Interview Question: Reverse an Array After Combining Its Elements

This article will help you practice your DataWeave skills in MuleSoft. Use the article as a tutorial for learning more about DataWeave.

By 
Gaurav Dubey user avatar
Gaurav Dubey
·
Jan. 20, 22 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
6.5K Views

Join the DZone community and get the full member experience.

Join For Free

This article will help you practice your DataWeave skills in MuleSoft. Use the article as a tutorial for learning more about DataWeave.

Let's get started. 

Input:

JSON
 
[

"uat", ["sit", "qa", "prod"]

]

Output:

[

  "prod",

  "qa",

  "sit",

  "uat"

]


Let's talk about the solution now.

In the first step, we will combine all the elements of an array into a single array using flatten function.

Step 1 Code:

DataWeave Script

 
%dw 2.0

output application/json

var combinedPayload = (flatten(payload))

---

combinedPayload


Step 1 Output:

JSON
 

[

  "uat",

  "sit",

  "qa",

  "prod"

]


In the second step, we will reverse the contents of an array using the range selector.

Step 2 Code:

DataWeave Script

 

%dw 2.0

output application/json

var combinedPayload = (flatten(payload))

---

combinedPayload[(sizeOf(combinedPayload)) -1 to 0]


Step 2 Output:

JSON
 
[

  "prod",

  "qa",

  "sit",

  "uat"

]


We have used sizeOf function to get the size of our combinedPayload along with the range selector to get the array in reverse format.

Happy Learning!

Data structure Element Interview (journalism)

Opinions expressed by DZone contributors are their own.

Related

  • DataWeave Interview Question: Concatenate Elements of an Array
  • Top 10 Algorithms for the Coding Interview (for Software Engineers)
  • Reversing an Array: An Exploration of Array Manipulation
  • Unlocking the Potential of Binary Search Trees with C# Programming

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!