05-15-2013 07:33 AM
I have a set of code that returns an array of two values. The next step in my code is to choose only one value based on a set of rules:
If both items are equal, return either one of the values.
If exactly one item is equal to 12, return the remaining value (12 could be in the first or second position)
Otherwise, always return the largest value.
I can map this out in my head and it seems fairly straightforward, but when I try to turn it into code, it becomes more complicated.
I have attached my attempt. Am I overthinking this?
Thanks for any help.
Solved! Go to Solution.
05-15-2013 07:52 AM - edited 05-15-2013 07:58 AM
c
05-15-2013 07:52 AM - edited 05-15-2013 07:53 AM
First of all, use the Array Max & Min to get the largest value. Coincidentally, if they are equal, the Max and Min will be the same value. So finding the Max will suffice for cases 1 and 3. So really, we just need to figure out if one of them is 12. Compare the array to 12. This will give you a boolean array. Now use the Boolean Array to Number to get a number and wire that number to a case structure. If the number is 1, then the first value was 12 and you should return the second value. If the number is 2, then the second value was 12 and you should return the first value. If the number is anything else, return the max of the array.
05-15-2013 09:30 AM
Thanks. That is definitely much cleaner than I was making it.
05-15-2013 05:21 PM - edited 05-15-2013 05:21 PM
For some reason I was thinking about this problem while washing the dishes and came up with another solution.