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
Newsletter
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

  • Measuring AI Impact at the Team Level
  • Vapi vs Retell AI vs LiveKit: Architecture, Latency, Pricing, and Developer Experience
  • An Overview of Data Pipeline Architecture
  • Member Spotlight: Srinivas Chippagiri

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  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
·
Sep. 13, 21 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
20.9K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

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

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • 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