Get a list, sorted in increasing order by the last element in each tuple from a given list of non-empty tuples

Certified Associate Developer

Write a program to get a list, sorted in increasing order by the last element

in each tuple from a given list of non-empty tuples.

Input: [(1, 3), (3, 2), (2, 1)]


Output: [(2, 1), (3, 2), (1, 3)]

  Discussion posts and replies are publicly visible

Parents
  • +1
    Certified Lead Developer

    Where do you guys get these assignments from? What is your solution?

    As it is a bit difficult to create list of lists in Appian, I use maps to define the tuples.

    a!localVariables(
      local!tuples: {
        a!map(a: 1, b: 3),
        a!map(a: 3, b: 2),
        a!map(a: 2, b: 1),
      },
      todatasubset(
        a!forEach(
          items: local!tuples,
          expression: a!map(
            tuple: fv!item,
            sort: fv!item.b
          )
        ),
        a!pagingInfo(
          startIndex: 1,
          batchSize: 1000,
          sort: a!sortInfo(
            field: "sort",
            ascending: true
          )
        )
      ).data.tuple
    )

Reply
  • +1
    Certified Lead Developer

    Where do you guys get these assignments from? What is your solution?

    As it is a bit difficult to create list of lists in Appian, I use maps to define the tuples.

    a!localVariables(
      local!tuples: {
        a!map(a: 1, b: 3),
        a!map(a: 3, b: 2),
        a!map(a: 2, b: 1),
      },
      todatasubset(
        a!forEach(
          items: local!tuples,
          expression: a!map(
            tuple: fv!item,
            sort: fv!item.b
          )
        ),
        a!pagingInfo(
          startIndex: 1,
          batchSize: 1000,
          sort: a!sortInfo(
            field: "sort",
            ascending: true
          )
        )
      ).data.tuple
    )

Children