check an array has mix of values

I have a condition where if a list contains only numbers as 10, i.e{10,10,10,10} I should  return 1 else If list contains any numbers apart from 10 i.e{23,50,60} I have to return   0 else if that list contains mix of 10 and other numbers {10,23,45} then I have to return as 2. how can i write this in expression rule ? 

  Discussion posts and replies are publicly visible

  • Sidharth, please test the code with different lists like local!array1,local!array2,local!mixedArray.wherecontains(10, local!array1),

    Replace the list name in the 

    a!localVariables(
    /* Values for testing*/
    local!array1: { 10, 10, 10 },
    local!array2: { 23, 50, 60 },
    local!mixedArray: { 10, 23, 45 },
    /*Checking results */
    local!howManyOccurrances: wherecontains(10, local!array1),
    local!isArrayHasAll10s: length(local!array1) = length(local!howManyOccurrances),
    if(
    /*If list contains same number, return 1*/
    local!isArrayHasAll10s,
    1,
    /*If list contains different numbers along with given number , return 2*/
    if(
    local!howManyOccurrances > 0,
    2,
    /*If list contains different numbers than the given number , return 0*/
    0
    )
    )
    )

    Note: When you use the logic in the implementation take care of the null checks

  • You can compare a list of values to a single value and it will return a list of booleans for each.

    and({10,10,10,10} = 10) => true

    and({10,10,10,11} = 10) => false

    or({10,10,10,11} = 10) => true

    or({23,50,60} = 10) => false

    Using an and() would check for all values equal 10. Using an or() would check for at least one value equals 10. That should get your three cases covered.