Skip to main content
Known Participant
January 10, 2024
Solved

Comparing two arrays

  • January 10, 2024
  • 8 replies
  • 9 views

Hi,

Is there any straightforward method to compare below two arrays in such a way that, SelectedAnswersArray[1]=correctAnswersArray[1] , SelectedAnswersArray[2]=correctAnswersArray[2] and SelectedAnswersArray[3]=correctAnswersArray[3] .

SelectedAnswersArray: {"a","c","b"}

correctAnswersArray: {"a","b","c"}

    Best answer by harshitb6843

    {"a","c","b"}={"a","b","c"}

    As unreal as it looks, just an equal operator will work. 

    8 replies

    stefanhelzle0001
    Brainy
    January 10, 2024

    Did you try a simple foreach() that compares the values on both lists by index? This will get you a list of booleans.

    Known Participant
    January 10, 2024

    Can we use foreach() inside a foreach() ?

    stefanhelzle0001
    Brainy
    January 10, 2024

    Sure, but why would you want to do that?

    harshitb6843
    Brainy
    January 10, 2024

    {"a","c","b"}={"a","b","c"}

    As unreal as it looks, just an equal operator will work. 

    Known Participant
    January 10, 2024

    oh great... Will try this approach also...

    Inspiring
    January 10, 2024

    Hi,
    Adding to Harshit's and Stefan's comments, you can also use Appian's OOTB function 'exact', which will help you, in case you need to compare in a case-sensitive manner.

    a!forEach(
      items: merge({ "a", "B", "C" }, { "a", "b", "C" }),
      expression: exact(fv!item[1], fv!item[2])
    )

    mathieud0001
    Brainy
    January 10, 2024

    Comparing two arrays returns a list of booleans. This might be a little better:

    a!localVariables(
      local!array1: { 1, 2, 3 },
      local!array2: { 1, 2, 3 },
      not(contains(local!array1 = local!array2, false))
    )

    rithanir5887
    Participating Frequently
    January 11, 2024

    Hello [mention:effa9f429a764d98b42411e7f964ed12:e9ed411860ed4f2ba0265705b8793d05] ,

    You can try this as well.

    a!localVariables(
      local!arr1:{1,2,4},
      local!arr2:{1,2,3},
      a!forEach(
        items: local!arr1,
        expression:fv!item=local!arr2[fv!index]
      )
    )