jslt icon indicating copy to clipboard operation
jslt copied to clipboard

max\min against arrays

Open samer1977 opened this issue 1 year ago • 1 comments

Hi,

Sorry maybe my brain still thinks the other way but how would you solve this problem: https://github.com/bazaarvoice/jolt/issues/700

I cant think of a way without having to create custom recursive max\min as in:

def max_array(array)

if(size($array)==0) null else if(size($array)==1) $array[0]

else max($array[0],max_array($array[1:]))

vs

{

"minPrice": min([for(.prices).price]) "minPrice": max([for(.prices).price])

}

Thanks

samer1977 avatar May 27 '24 17:05 samer1977

You're right that there is no other way at the moment. max() and min() should perhaps also have single-argument versions that accept an array.

larsga avatar May 27 '24 17:05 larsga