<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Jabhay on Medium]]></title>
        <description><![CDATA[Stories by Jabhay on Medium]]></description>
        <link>https://medium.com/@jabhay81?source=rss-2cd7f0de923f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*jaTdPc1uCfEzPKJc</url>
            <title>Stories by Jabhay on Medium</title>
            <link>https://medium.com/@jabhay81?source=rss-2cd7f0de923f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 00:34:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jabhay81/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Dataweave Questions for Practice- Part 3]]></title>
            <link>https://medium.com/@jabhay81/dataweave-questions-for-practice-part-3-a527224bba4f?source=rss-2cd7f0de923f------2</link>
            <guid isPermaLink="false">https://medium.com/p/a527224bba4f</guid>
            <category><![CDATA[dataweave-questions]]></category>
            <category><![CDATA[dataweave-interview]]></category>
            <category><![CDATA[dataweave-practice]]></category>
            <category><![CDATA[dataweave]]></category>
            <dc:creator><![CDATA[Jabhay]]></dc:creator>
            <pubDate>Tue, 13 May 2025 16:12:10 GMT</pubDate>
            <atom:updated>2025-05-13T16:21:11.533Z</atom:updated>
            <content:encoded><![CDATA[<p>Input:</p><pre>[<br>  {&quot;title&quot;: &quot;Song1&quot;, &quot;duration&quot;: &quot;00:30&quot;},<br>  {&quot;title&quot;: &quot;Song2&quot;, &quot;duration&quot;: &quot;01:15&quot;},<br>  {&quot;title&quot;: &quot;Song3&quot;, &quot;duration&quot;: &quot;01:15&quot;}<br>]</pre><p>Output:</p><pre>3</pre><p>Dataweave code:</p><pre>%dw 2.0<br>output application/json<br>fun abc(a,b) = if(a&gt;0) a*60 + b else b<br>var a = payload map ((item, index) -&gt; item pluck ((value, key, index) -&gt; value) ) map ((item, index) -&gt; item[1])<br>var b = a map ((item, index) -&gt; item splitBy  &quot;:&quot;)<br>---<br>((0 to 2) map (abc(b[$][0], b[$][1])) reduce ($$ +$)) as Number / 60</pre><p>2.</p><p>Input:</p><pre>&quot;Even if they are djinns, I will get djinns that can outdjinn them.&quot;</pre><p>Output:</p><pre>[<br>  &quot;Even&quot;,<br>  &quot;if&quot;,<br>  &quot;they&quot;,<br>  &quot;are&quot;,<br>  &quot;djinns&quot;,<br>  &quot;I&quot;,<br>  &quot;will&quot;,<br>  &quot;get&quot;,<br>  &quot;djinns&quot;,<br>  &quot;that&quot;,<br>  &quot;can&quot;,<br>  &quot;outdjinn&quot;,<br>  &quot;them&quot;<br>]</pre><p>Dataweave code:</p><pre>%dw 2.0<br>output application/json<br>---<br>(payload replace /[^\w\s]/ with &quot;&quot;) splitBy  &quot; &quot;</pre><p>3.</p><p>Input:</p><pre>{<br>    &quot;StartDate&quot; : &quot;2019-11-30&quot;,<br>    &quot;EndDate&quot; : &quot;2020-01-06&quot;<br>}</pre><p>Output:</p><pre>[<br>  {<br>    &quot;November&quot;: [<br>      &quot;2019-11-30&quot;<br>    ]<br>  },<br>  {<br>    &quot;December&quot;: [<br>      &quot;2019-12-01&quot;,<br>      &quot;2019-12-02&quot;,<br>      &quot;2019-12-03&quot;,<br>      &quot;2019-12-04&quot;,<br>      &quot;2019-12-05&quot;,<br>      &quot;2019-12-06&quot;,<br>      &quot;2019-12-07&quot;,<br>      &quot;2019-12-08&quot;,<br>      &quot;2019-12-09&quot;,<br>      &quot;2019-12-10&quot;,<br>      &quot;2019-12-11&quot;,<br>      &quot;2019-12-12&quot;,<br>      &quot;2019-12-13&quot;,<br>      &quot;2019-12-14&quot;,<br>      &quot;2019-12-15&quot;,<br>      &quot;2019-12-16&quot;,<br>      &quot;2019-12-17&quot;,<br>      &quot;2019-12-18&quot;,<br>      &quot;2019-12-19&quot;,<br>      &quot;2019-12-20&quot;,<br>      &quot;2019-12-21&quot;,<br>      &quot;2019-12-22&quot;,<br>      &quot;2019-12-23&quot;,<br>      &quot;2019-12-24&quot;,<br>      &quot;2019-12-25&quot;,<br>      &quot;2019-12-26&quot;,<br>      &quot;2019-12-27&quot;,<br>      &quot;2019-12-28&quot;,<br>      &quot;2019-12-29&quot;,<br>      &quot;2019-12-30&quot;,<br>      &quot;2019-12-31&quot;<br>    ]<br>  },<br>  {<br>    &quot;January&quot;: [<br>      &quot;2020-01-01&quot;,<br>      &quot;2020-01-02&quot;,<br>      &quot;2020-01-03&quot;,<br>      &quot;2020-01-04&quot;,<br>      &quot;2020-01-05&quot;,<br>      &quot;2020-01-06&quot;<br>    ]<br>  }<br>]</pre><p>Dataweave code:</p><pre>%dw 2.0<br>import * from dw::core::Dates<br>import * from dw::core::Periods<br>output application/json<br>var a = ((0 to daysBetween(payload.StartDate,payload.EndDate)) map ({<br>    &quot;Date&quot; : (payload.StartDate + days($)) ,<br>    &quot;Month&quot; : (payload.StartDate + days($)) as String {format : &quot;MMMM&quot;}<br>})) groupBy ((item, index) -&gt; item.Month)<br>---<br>a pluck ((value, key, index) -&gt; (key) : value.Date)</pre><p>4.</p><p>Input:</p><pre>&quot;Abhay is a Mule developer. Mule is very very easy, Abhay knows Mule very well.&quot;</pre><p>Output:</p><pre><br>{<br>  &quot;Abhay&quot;: 2,<br>  &quot;is&quot;: 2,<br>  &quot;a&quot;: 1,<br>  &quot;Mule&quot;: 3,<br>  &quot;developer&quot;: 1,<br>  &quot;very&quot;: 3,<br>  &quot;easy&quot;: 1,<br>  &quot;knows&quot;: 1,<br>  &quot;well&quot;: 1<br>}</pre><p>Dataweave code:</p><p>Sol 1:</p><pre>%dw 2.0<br>output application/json<br>import * from dw::core::Arrays<br>var cleanPayload = payload replace  /[^\w\s]/ with &quot;&quot;<br>var splitPayload = (cleanPayload splitBy  &quot; &quot;)<br>var distinctPayload = splitPayload distinctBy ((item, index) -&gt; item)<br>---<br>(0 to sizeOf(distinctPayload)-1) map({<br>    (distinctPayload[$$]) : splitPayload countBy ((param_1) -&gt; param_1 == distinctPayload[$$])<br>}) reduce ((item, accumulator) -&gt; accumulator ++ item)</pre><p>Sol 2</p><pre>%dw 2.0<br>output application/json<br>import * from dw::core::Arrays<br>var cleanPayload = payload replace  /[^\w\s]/ with &quot;&quot;<br>var splitPayload = (cleanPayload splitBy  &quot; &quot;)<br>var distinctPayload = splitPayload distinctBy ((item, index) -&gt; item)<br>---<br>distinctPayload map ((item, index) -&gt; {<br>    (distinctPayload[index]) : sizeOf(splitPayload filter ((item1, index) -&gt; item1 == item))<br>}) reduce ($$ ++ $)</pre><p>5.</p><p>Input:</p><pre>[&quot;a&quot;,&quot;b&quot;, &quot;a&quot;, &quot;d&quot;]</pre><p>Output:</p><pre>[<br>  &quot;a2&quot;,<br>  &quot;b1&quot;,<br>  &quot;d1&quot;<br>]</pre><p>Dataweave code:</p><p>Sol 1:</p><pre>%dw 2.0<br>output application/json<br>import * from dw::core::Arrays<br>var a = payload distinctBy ((item, index) -&gt; item)<br>---<br>(0 to sizeOf(a)-1) map ( a[$$] ++ sizeOf(payload filter ((item, index) -&gt; item == a[$$])) )</pre><p>Sol 2:</p><pre>%dw 2.0<br>output application/json<br>import * from dw::core::Arrays<br>var a = payload distinctBy ((item, index) -&gt; item)<br>---<br>(0 to sizeOf(a)-1) map ( a[$$] ++  (payload countBy ((param_1) -&gt; param_1 == a[$$])) )</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a527224bba4f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dataweave Questions for Practice- Part 2]]></title>
            <link>https://medium.com/@jabhay81/dataweave-questions-for-practice-part-2-7410fbac826d?source=rss-2cd7f0de923f------2</link>
            <guid isPermaLink="false">https://medium.com/p/7410fbac826d</guid>
            <category><![CDATA[dataweave-practice]]></category>
            <category><![CDATA[dataweave-interview]]></category>
            <dc:creator><![CDATA[Jabhay]]></dc:creator>
            <pubDate>Sat, 26 Apr 2025 13:04:25 GMT</pubDate>
            <atom:updated>2025-04-28T03:33:34.755Z</atom:updated>
            <content:encoded><![CDATA[<ol><li>Check if a number is a Armstrong Number or not.</li></ol><p>Topics to learn: pow function</p><p>Input:</p><pre>[153]</pre><p>Output:</p><pre>&quot;ArmStrong&quot;</pre><p>Dataweave code:</p><pre>%dw 2.0<br>output application/json<br>var armNum = (0 to sizeOf(payload[0])-1) map ( payload[0][$] pow  sizeOf(payload[0])) reduce ($$ + $)<br>---<br>if (payload[0] == armNum) &quot;ArmStrong&quot; else &quot;Not ArmStrong&quot;</pre><p>2. Check if a number is a palindrome number or not.</p><p>Input:</p><pre>[121]</pre><p>Output:</p><pre>&quot;Palindrome&quot;</pre><p>Dataweave code:</p><pre>%dw 2.0<br>output application/json<br>---<br>if (payload[0][0 to -1] == payload[0][-1 to 0]) &quot;Palindrome&quot; else &quot;Not palindrome&quot;</pre><p>3. Calculate factorial of a number</p><p>Input:</p><pre>5</pre><p>Output:</p><pre>120</pre><p>Dataweave code:</p><pre>%dw 2.0<br>output application/json<br>---<br>(1 to payload) reduce ($$ * $)</pre><pre>%dw 2.0<br>output application/json<br>fun fact(n) = if(n&lt;1) 1 else n*fact(n-1)<br>---<br>fact(payload)</pre><p>4. Print Fibonacci Series</p><p>Input:</p><pre>5</pre><p>Output:</p><pre>[<br>  0,<br>  1,<br>  1,<br>  2,<br>  3,<br>  5<br>]</pre><p>Dataweave code:</p><pre>%dw 2.0<br>output application/json<br>fun fibo(n) = if(n==0) 0 else if (n==1) 1 else (fibo(n-1) + fibo(n-2))<br>---<br>(0 to payload-1) map(fibo($))</pre><p>5. Print Below pattern</p><p>Input:</p><pre>6</pre><p>Output:</p><pre>  &quot;1&quot;, <br>  &quot;1 2&quot;, <br>  &quot;1 2 3&quot;, <br>  &quot;1 2 3 4&quot;, <br>  &quot;1 2 3 4 5&quot;, <br>  &quot;1 2 3 4 5 6&quot;</pre><p>Dataweave code:</p><pre>%dw 2.0<br>output application/json<br>fun pattern(n) =  (if(n&gt;0) (n as String ++ &quot; &quot; ++ pattern(n-1)) else &quot;&quot;)<br>---<br>(1 to payload) map (trim(pattern($)[-1 to 0]))</pre><p>6. Check if string givens are Anargams.</p><p>If two strings have the same set of characters in a different order, they are anagrams.</p><p>Input:</p><pre>[&quot;listen&quot; , &quot;silent&quot;]</pre><p>Output:</p><pre>&quot;Anargam&quot;</pre><p>Dataweave code:</p><pre>%dw 2.0<br>output application/json<br>fun order(n) = (n splitBy &quot;&quot;) orderBy ((item, index) -&gt; item)<br>var anargam = (0 to sizeOf(payload)-1) map (order(payload[$])) map ((item, index) -&gt; item joinBy  &quot;&quot;)<br>---<br>if(anargam[0] == anargam[1]) &quot;Anargam&quot; else &quot;NotAnargam&quot;</pre><p>7. If condition without else</p><p>Input:</p><pre>{<br>    &quot;Tech&quot; : &quot;IPhone&quot;,<br>    &quot;Brand&quot; : &quot;Apple&quot;<br>}</pre><p>Output:</p><pre>&quot;IPhone&quot;</pre><p>Dataweave code:</p><pre>%dw 2.0<br>output application/json<br>---<br>[(payload.Tech) if(payload.Brand == &quot;Apple&quot;)][0]</pre><p>8. Check if a number is a prime number</p><p>Input:</p><pre>5</pre><p>Output:</p><pre>&quot;Prime&quot;</pre><p>Dataweave code:</p><pre>%dw 2.0<br>output application/json<br>fun isPrime(n) = (2 to n-1) map( if((n mod $) == 0) 0 else 1)<br>---<br>if(isPrime(payload) contains(0)) &quot;NotPrime&quot; else &quot;Prime&quot;</pre><p>9. Check if a number is a perfect square or not.</p><p>Input:</p><pre>16</pre><p>Output:</p><pre>&quot;PerfectSquare&quot;</pre><p>Dataweave code:</p><pre>%dw 2.0<br>output application/json<br>---<br>if(isInteger((payload pow  0.5))) &quot;PerfectSquare&quot; else &quot;Not a Perfect Square&quot;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7410fbac826d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dataweave Questions for Practice- Part 1]]></title>
            <link>https://medium.com/@jabhay81/dataweave-questions-for-practice-interview-5b6a35d984e6?source=rss-2cd7f0de923f------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b6a35d984e6</guid>
            <dc:creator><![CDATA[Jabhay]]></dc:creator>
            <pubDate>Wed, 19 Feb 2025 17:30:18 GMT</pubDate>
            <atom:updated>2025-06-24T02:40:47.771Z</atom:updated>
            <content:encoded><![CDATA[<ol><li>Print you name 10 times.</li></ol><p>Topics to learn: Map Operator</p><p>Input:</p><pre>&quot;Abhay&quot;</pre><p>Output:</p><pre>[<br>  &quot;Abhay&quot;,<br>  &quot;Abhay&quot;,<br>  &quot;Abhay&quot;,<br>  &quot;Abhay&quot;,<br>  &quot;Abhay&quot;,<br>  &quot;Abhay&quot;,<br>  &quot;Abhay&quot;,<br>  &quot;Abhay&quot;,<br>  &quot;Abhay&quot;,<br>  &quot;Abhay&quot;<br>]</pre><p>Dataweave code:</p><pre>%dw 2.0<br>output application/json<br>---<br>(1 to 10) map (payload)</pre><p>2. Take array of marks and name as input and calculate the result as pass or fail.</p><p>Topics to learn: creating function, pluck, reduce, map</p><p>Input:</p><pre>[{<br>    &quot;Name&quot; : &quot;Abhay&quot;,<br>    &quot;Marks&quot; : {<br>        &quot;Maths&quot; : 95,<br>        &quot;Science&quot; : 80,<br>        &quot;English&quot; : 98<br>    }<br>},<br>{<br>    &quot;Name&quot; : &quot;Anant&quot;,<br>    &quot;Marks&quot; : {<br>        &quot;Maths&quot; : 56,<br>        &quot;Science&quot; : 40,<br>        &quot;English&quot; : 30<br>    }<br>},<br>{<br>    &quot;Name&quot; : &quot;Amandeep&quot;,<br>    &quot;Marks&quot; : {<br>        &quot;Maths&quot; : 98,<br>        &quot;Science&quot; : 88,<br>        &quot;English&quot; : 84<br>    }<br>}]</pre><p>Output:</p><pre>{<br>  &quot;Abhay&quot;: &quot;PASS&quot;,<br>  &quot;Anant&quot;: &quot;FAIL&quot;,<br>  &quot;Amandeep&quot;: &quot;PASS&quot;<br>}</pre><p>Dataweave code:</p><pre>%dw 2.0<br>output application/json<br>fun avg(marksObject) = ((marksObject pluck ((value, key, index) -&gt; value )) reduce ($$ + $))/sizeOf(marksObject)<br>fun result(marks) = if (marks &gt;80) &quot;PASS&quot; else &quot;FAIL&quot;<br>---<br>(payload map ((item, index) -&gt; {<br>    (item.Name) : result(avg(item.Marks))<br>})) reduce ($$ ++ $)</pre><p>3. Swap key and values</p><p>Topics to learn: mapObject operator</p><p>Input:</p><pre>{<br>    &quot;firstName&quot; : &quot;Abhay&quot;,<br>    &quot;lastName&quot; : &quot;Joshi&quot;<br>}</pre><p>Output:</p><pre>{<br>  &quot;Abhay&quot;: &quot;firstName&quot;,<br>  &quot;Joshi&quot;: &quot;lastName&quot;<br>}</pre><p>Dataweave code:</p><pre>%dw 2.0<br>output application/json<br>---<br>payload mapObject ((value, key, index) -&gt; {<br>    (value) : key<br>} )</pre><p>4. Break a object to arrays of object</p><p>Topics to learn: pluck operator</p><p>Input:</p><pre>{<br>&quot;Name&quot;: &quot;Shubham&quot;,<br>&quot;Marks&quot;: 90,<br>&quot;Name&quot;: &quot;AShish&quot;,<br>&quot;Marks&quot;: 50,<br>&quot;Name&quot;: &quot;Divya&quot;,<br>&quot;Marks&quot;: 80<br>}</pre><p>Output:</p><pre>[<br>  {<br>    &quot;Name&quot;: &quot;Shubham&quot;,<br>    &quot;Marks&quot;: 90<br>  },<br>  {<br>    &quot;Name&quot;: &quot;AShish&quot;,<br>    &quot;Marks&quot;: 50<br>  },<br>  {<br>    &quot;Name&quot;: &quot;Divya&quot;,<br>    &quot;Marks&quot;: 80<br>  }<br>]</pre><p>Dataweave code:</p><pre>%dw 2.0<br>output application/json<br>var a = payload pluck ((value, key, index) -&gt; value)<br>---<br>(1 to (sizeOf(payload)/2)) map ({<br>    &quot;Name&quot; : a[$$*2],<br>    &quot;Marks&quot; : a[$$*2+1]<br>})</pre><p>5. Out of list of various airlines find all the flights with minimum fares for a particular destination</p><p>Topics to learn: min and filter</p><p>Input:</p><pre>[{<br>    &quot;Operator&quot; : &quot;Indigo&quot;,<br>    &quot;Destination&quot; : &quot;Hyd&quot;,<br>    &quot;Price&quot; : 5000<br>},<br>{<br>    &quot;Operator&quot; : &quot;Vistara&quot;,<br>    &quot;Destination&quot; : &quot;Hyd&quot;,<br>    &quot;Price&quot; : 5000<br>},<br>{<br>    &quot;Operator&quot; : &quot;Indigo&quot;,<br>    &quot;Destination&quot; : &quot;Blr&quot;,<br>    &quot;Price&quot; : 6000<br>},<br>{<br>    &quot;Operator&quot; : &quot;Air India&quot;,<br>    &quot;Destination&quot; : &quot;Hyd&quot;,<br>    &quot;Price&quot; : 9000<br>}]</pre><p>Output:</p><pre>[<br>  {<br>    &quot;Operator&quot;: &quot;Indigo&quot;,<br>    &quot;Destination&quot;: &quot;Hyd&quot;,<br>    &quot;Price&quot;: 5000<br>  },<br>  {<br>    &quot;Operator&quot;: &quot;Vistara&quot;,<br>    &quot;Destination&quot;: &quot;Hyd&quot;,<br>    &quot;Price&quot;: 5000<br>  }<br>]</pre><p>Dataweave code:</p><pre>%dw 2.0<br>output application/json<br>---<br>payload filter ((item, index) -&gt; ((item.Price == min(payload.Price)) and (item.Destination == &quot;Hyd&quot;)) )</pre><p>6. Convert nested array to a single array</p><p>Topics to learn: flatmap function</p><p>Input:</p><pre>[1,[2,3],4,[5,6,[7,8]]]</pre><p>Output:</p><pre>[<br>  1,<br>  2,<br>  3,<br>  4,<br>  5,<br>  6,<br>  7,<br>  8<br>]</pre><p>Dataweave code:</p><pre>%dw 2.0<br>output application/json<br>---<br>(payload flatMap ((item1, index) -&gt; item1)) flatMap ((item2, index) -&gt; item2)</pre><pre>%dw 2.0<br>output application/json<br>fun deepFlaten(arr) = arr flatMap ((item, index) -&gt; if(item is Array) deepFlaten(item) else item)<br>---<br>deepFlaten(payload)</pre><p>7. Convert xml payload to json with attributes</p><p>Topics to learn: writeAttributes=true</p><p>Input:</p><pre>&lt;Order id=&quot;12345&quot; status=&quot;Shipped&quot;&gt;<br>    &lt;Customer name=&quot;John Doe&quot; email=&quot;johndoe@example.com&quot;/&gt;<br>    &lt;Items&gt;<br>        &lt;Item id=&quot;A1001&quot; category=&quot;Electronics&quot;&gt;<br>            &lt;Name&gt;Smartphone&lt;/Name&gt;<br>            &lt;Price currency=&quot;USD&quot;&gt;699.99&lt;/Price&gt;<br>            &lt;Quantity&gt;1&lt;/Quantity&gt;<br>        &lt;/Item&gt;<br>        &lt;Item id=&quot;B2002&quot; category=&quot;Accessories&quot;&gt;<br>            &lt;Name&gt;Wireless Charger&lt;/Name&gt;<br>            &lt;Price currency=&quot;USD&quot;&gt;49.99&lt;/Price&gt;<br>            &lt;Quantity&gt;2&lt;/Quantity&gt;<br>        &lt;/Item&gt;<br>    &lt;/Items&gt;<br>    &lt;Shipping method=&quot;Express&quot; carrier=&quot;FedEx&quot;&gt;<br>        &lt;Address country=&quot;USA&quot;&gt;<br>            &lt;Street&gt;123 Main St&lt;/Street&gt;<br>            &lt;City&gt;New York&lt;/City&gt;<br>            &lt;State&gt;NY&lt;/State&gt;<br>            &lt;Zip&gt;10001&lt;/Zip&gt;<br>        &lt;/Address&gt;<br>    &lt;/Shipping&gt;<br>&lt;/Order&gt;</pre><p>Output:</p><pre>{<br>  &quot;Order&quot;: {<br>    &quot;@id&quot;: &quot;12345&quot;,<br>    &quot;@status&quot;: &quot;Shipped&quot;,<br>    &quot;Customer&quot;: {<br>      &quot;@name&quot;: &quot;John Doe&quot;,<br>      &quot;@email&quot;: &quot;johndoe@example.com&quot;,<br>      &quot;__text&quot;: null<br>    },<br>    &quot;Items&quot;: {<br>      &quot;Item&quot;: {<br>        &quot;@id&quot;: &quot;A1001&quot;,<br>        &quot;@category&quot;: &quot;Electronics&quot;,<br>        &quot;Name&quot;: &quot;Smartphone&quot;,<br>        &quot;Price&quot;: {<br>          &quot;@currency&quot;: &quot;USD&quot;,<br>          &quot;__text&quot;: &quot;699.99&quot;<br>        },<br>        &quot;Quantity&quot;: &quot;1&quot;<br>      },<br>      &quot;Item&quot;: {<br>        &quot;@id&quot;: &quot;B2002&quot;,<br>        &quot;@category&quot;: &quot;Accessories&quot;,<br>        &quot;Name&quot;: &quot;Wireless Charger&quot;,<br>        &quot;Price&quot;: {<br>          &quot;@currency&quot;: &quot;USD&quot;,<br>          &quot;__text&quot;: &quot;49.99&quot;<br>        },<br>        &quot;Quantity&quot;: &quot;2&quot;<br>      }<br>    },<br>    &quot;Shipping&quot;: {<br>      &quot;@method&quot;: &quot;Express&quot;,<br>      &quot;@carrier&quot;: &quot;FedEx&quot;,<br>      &quot;Address&quot;: {<br>        &quot;@country&quot;: &quot;USA&quot;,<br>        &quot;Street&quot;: &quot;123 Main St&quot;,<br>        &quot;City&quot;: &quot;New York&quot;,<br>        &quot;State&quot;: &quot;NY&quot;,<br>        &quot;Zip&quot;: &quot;10001&quot;<br>      }<br>    }<br>  }<br>}</pre><p>Dataweave code:</p><pre>%dw 2.0<br>output application/json writeAttributes=true<br>---<br>payload</pre><p>8. Reverse words in a sentence</p><p>Topics to learn: splitBy, joinBy</p><p>Input:</p><pre>&quot;We should obey traffic rules&quot;</pre><p>Output:</p><pre>&quot;rules traffic obey should We&quot;</pre><p>Dataweave code:</p><pre>%dw 2.0<br>output application/json <br>---<br>((payload splitBy &quot; &quot;)[-1 to 0]) joinBy  &quot; &quot;</pre><p>9. Take out initals of a name and print surname fully.</p><p>Topics to learn: capitalize</p><p>Input:</p><pre>&quot;Arnav singh raizada&quot;</pre><p>Output:</p><pre>&quot;A.S.Raizada&quot;</pre><p>Dataweave code:</p><pre>%dw 2.0<br>output application/json <br>import * from dw::core::Strings<br>---<br>upper((((payload splitBy &quot; &quot;)[0 to -2] map ((item, index) -&gt; item[0]))) joinBy  &quot;.&quot;) ++ &quot;.&quot; ++ capitalize((payload splitBy  &quot; &quot;)[-1])</pre><p>10. Calculate highest salary from each department</p><p>Input:</p><pre>[<br> {<br>  &quot;name&quot;: &quot;Abhay&quot;,<br>  &quot;salary&quot;: 4000,<br>  &quot;department&quot;: &quot;IT&quot;<br> },<br> {<br>  &quot;name&quot;: &quot;Aman&quot;,<br>  &quot;salary&quot;: 400,<br>  &quot;department&quot;: &quot;IT&quot;<br> },<br> {<br>  &quot;name&quot;: &quot;Anant&quot;,<br>  &quot;salary&quot;: 5500,<br>  &quot;department&quot;: &quot;Sales&quot;<br> },<br> {<br>  &quot;name&quot;: &quot;Tanya&quot;,<br>  &quot;salary&quot;: 2000,<br>  &quot;department&quot;: &quot;Marketing&quot;<br> },<br> {<br>  &quot;name&quot;: &quot;Ram&quot;,<br>  &quot;salary&quot;: 2000,<br>  &quot;department&quot;: &quot;Marketing&quot;<br> }<br>]</pre><p>Output:</p><pre>{<br>  &quot;IT&quot;: [<br>    {<br>      &quot;name&quot;: &quot;Abhay&quot;,<br>      &quot;salary&quot;: 4000,<br>      &quot;department&quot;: &quot;IT&quot;<br>    }<br>  ],<br>  &quot;Sales&quot;: [<br>    {<br>      &quot;name&quot;: &quot;Anant&quot;,<br>      &quot;salary&quot;: 5500,<br>      &quot;department&quot;: &quot;Sales&quot;<br>    }<br>  ],<br>  &quot;Marketing&quot;: [<br>    {<br>      &quot;name&quot;: &quot;Tanya&quot;,<br>      &quot;salary&quot;: 2000,<br>      &quot;department&quot;: &quot;Marketing&quot;<br>    },<br>    {<br>      &quot;name&quot;: &quot;Ram&quot;,<br>      &quot;salary&quot;: 2000,<br>      &quot;department&quot;: &quot;Marketing&quot;<br>    }<br>  ]<br>}</pre><p>Dataweave code:</p><pre>%dw 2.0<br>output application/json <br>import * from dw::core::Strings<br>var deptdata=(payload groupBy ((item1, index) -&gt; item1.department))<br>var maxSalaries = (deptdata pluck ((value, key, index) -&gt; value map ((item, index) -&gt; (item.salary)))) map ((item2, index) -&gt; max(item2))<br>---<br>deptdata mapObject ((value, key, index) -&gt; (key) : value filter ((item3, index1) -&gt; item3.salary==maxSalaries[index]))</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b6a35d984e6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>