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
  • 0
    Certified Senior Developer

    You can create a local variable of Map type and use to data subset to sort the array descending and get the 1st index value

    a!localVariables(
      local!listOfInts: {
        a!map(num: 5),
        a!map(num: 6),
        a!map(num: 2),
        a!map(num: 1),
        a!map(num: 10),
        a!map(num: 7)
      },
      index(
        index(
          todatasubset(
            local!listOfInts,
            a!pagingInfo(1, - 1, a!sortInfo("num", false()))
          ).data,
          "num",
          {}
        ),
        1,
        {}
      )
    )

Reply
  • 0
    Certified Senior Developer

    You can create a local variable of Map type and use to data subset to sort the array descending and get the 1st index value

    a!localVariables(
      local!listOfInts: {
        a!map(num: 5),
        a!map(num: 6),
        a!map(num: 2),
        a!map(num: 1),
        a!map(num: 10),
        a!map(num: 7)
      },
      index(
        index(
          todatasubset(
            local!listOfInts,
            a!pagingInfo(1, - 1, a!sortInfo("num", false()))
          ).data,
          "num",
          {}
        ),
        1,
        {}
      )
    )

Children