Appian Community and Appian Academy are being upgraded. From July 24–August 3, the Appian Community will be in read-only mode. During this time, the site will be read-only and user registration will be disabled. We apologize for any inconvenience this may cause, but a more secure, stable, and performant Community experience is coming soon!

The new Appian Community launches August 3, followed by Appian Academy on August 7. During the migration, Appian Community Edition, Appian Academy, Documentation, Certifications, Instructor-led Customer Training, Partner Sales Training & Accreditation, and Forum (for Appian Partners and Customers only) will remain available.

How to find the max no from an array without using Max() ?

Hi dear,

I have written code like in the picture, I just want to print the max no without using max function.

  Discussion posts and replies are publicly visible

Parents Reply
  • You could do this with looping, but max() is by far the easiest and fastest method.  I would also be interested in the use case reasoning to avoid max().

    deepakg's example with todatasubset() sorting is a commonly used solution for similar items as well.

    Additionally, max value from nested a!forEach():

    a!localVariables(
      local!list: {1,3,8,6,5,2},
      
      index(
        reject(
          fn!isnull,
          a!forEach(
            items: local!list,
            expression: {
              a!localVariables(
                local!item: fv!item,
                if(
                  count(
                    wherecontains(
                      true,
                      a!forEach(
                        items: local!list,
                        expression: toboolean(fv!item<local!item)
                      )
                    )
                  )=count(local!list)-1,
                  fv!item,
                  null
                )
              )
            }
          )
        ),
        1,
        null
      )
    )

    Max with sortintegerarray():

    index(
      sortintegerarray({1,3,8,6,5},true),
      1,
      null
    )

Children
No Data