Forum Discussion
adam_gataev - since you have it in an array, you can use the Array.reduce() method to get the min or max value out of the array. It would look like this:
$dateArray.reduce ((accum,cur)=> accum == null || accum > cur ? cur : accum, null)
Note that this also uses the ternary operator for the if/then/else condition to determine which value is greater when comparing the array elements. One nice feature of this method is that it doesn't matter what the data type of the values are, as long as they are comparable.
There are other ways you could do this, but this was my initial thought. If you're interested, I've attached an expression library that I created a while back and share with many of my clients as it has many common functions that have been requested. To use the expr lib, just include it into the pipeline properties, then your expressions to get the min/max values just use the string.min() and string.max() methods. Note the use of the spread operator to expand the array to individual values since the expr lib method is expecting a list of values rather than an array.
Hope this helps!
- adam_gataev2 years agoNew Contributor II
Hi koryknick,
It worked, thank you so much! I am not sure if it will be a problem, but I just put the expression in the mapper snap instead of using an expression library file.
Is there maybe a reason other than the readability benefit why you would use an expression library file?