conventional method to find the gratest number using for loop
Discussion posts and replies are publicly visible
Here is an O(n) approach implemented like C, employing a temporary variable to store the current maximum (rule input ). In this implementation, a recursive approach has been utilized. If you have any questions or need further clarification, feel free to ask. if( ri!currentIndex > length(ri!arr), ri!currentMax, rule!maxNum( arr: ri!arr, currentMax: if( ri!currentMax > ri!arr[ri!currentIndex], ri!currentMax, ri!arr[ri!currentIndex] ), currentIndex: ri!currentIndex + 1 ) ) /*arr: array in which we needs to find max num*/ /*currentMax: first element of array*/ /*current index: first index of array (1 in case of appian)*/
if( ri!currentIndex > length(ri!arr), ri!currentMax, rule!maxNum( arr: ri!arr, currentMax: if( ri!currentMax > ri!arr[ri!currentIndex], ri!currentMax, ri!arr[ri!currentIndex] ), currentIndex: ri!currentIndex + 1 ) ) /*arr: array in which we needs to find max num*/ /*currentMax: first element of array*/ /*current index: first index of array (1 in case of appian)*/
result->
I'd point out that you're not actually declaring any local variable in this rule, and thus it's unnecessary to even call a!localVariables() other than potentially if you want to add one in the future for easier understanding.
I was going with a different approach with local variables and forgot to remove a!localVariables() when I moved to rule inputs.