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
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • JS (React) Technical Interview: Structure, Coding Tasks Examples, Tips
  • DataWeave Interview Question: Reverse an Array After Combining Its Elements
  • DataWeave Interview Question: Concatenate Elements of an Array
  • DataWeave Interview Question: Compare IDs From Two Arrays and Create a New Array

Trending

  • Persistent Memory for AI Agents Using LangChain's Deep Agents
  • 7 Technology Waves I’ve Seen in 30 Years of Software — Will AI Be the Next Real Transformation?
  • Metal and Skins
  • Engineering Closed-Loop Graph-RAG Systems, Part 2: From Prompts to Rules
  1. DZone
  2. Culture and Methodologies
  3. Career Development
  4. DataWeave Interview Question: Find the Greatest and Smallest Number of an Array

DataWeave Interview Question: Find the Greatest and Smallest Number of an Array

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
·
Sep. 13, 21 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
20.7K 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. Let's get started.

Input:

[1,2,3,4,5]

Output:

5

Let's talk about the solution now.

In the first step, we will store the first value into a variable.

In the second step, we will use a reduce function to iterate over an array and find the greatest number.

Code for Greatest Number:

%dw 2.0

output application/json

var startNumber=payload[0]

---

payload reduce ((item, accumulator=startNumber) -> if(item>accumulator) item else accumulator)

The above code will provide us with the Greatest Number of an Array. We will use the below code to find the Smallest Number.

Code for Smallest Number:

%dw 2.0

output application/json

var startNumber=payload[0]

---

payload reduce ((item, accumulator=startNumber) -> if(item<accumulator) item else accumulator)

Output:

1

Happy Learning!

Data structure Interview (journalism)

Opinions expressed by DZone contributors are their own.

Related

  • JS (React) Technical Interview: Structure, Coding Tasks Examples, Tips
  • DataWeave Interview Question: Reverse an Array After Combining Its Elements
  • DataWeave Interview Question: Concatenate Elements of an Array
  • DataWeave Interview Question: Compare IDs From Two Arrays and Create a New Array

Partner Resources

×

Comments

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

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

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 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook