Skip to main content
Known Participant
Jan 10, 2024 4:12 PM UTC
Solved

Comparing two arrays

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"}

    harshitb6843
    Brainy
    Jan 10, 2024 4:21 PM UTC

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

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

    8 replies

    stefanhelzle0001
    Brainy
    Jan 10, 2024 4:15 PM UTC

    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
    Jan 10, 2024 4:23 PM UTC

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

    stefanhelzle0001
    Brainy
    Jan 10, 2024 4:24 PM UTC

    Sure, but why would you want to do that?

    harshitb6843
    Brainy
    Jan 10, 2024 4:21 PM UTC

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

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

    Known Participant
    Jan 10, 2024 4:44 PM UTC

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

    Inspiring
    Jan 10, 2024 7:31 PM UTC

    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
    Genius
    Jan 10, 2024 11:43 PM UTC

    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
    Jan 11, 2024 6:47 AM UTC

    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]
      )
    )