[pshaiCmd] ArrayFilter2

0 497 Views No Comments 2 years ago
HTS CLOUDSTABLE
  • ArrayFilter command that works with numbers and text too.

    Example of use:

    
    -- build test arrays
    local array1 = {} -- will contain GUID values as text
    local array2 = {} -- will contain numbers
     
    for i = 1, 10 do
        array1[i] = NewGuid()
        array2[i] = i
    end
     
    -- filter array1
    Log('---- Array1 ----')
    Log(array1) -- log the unfiltered array
    
    -- grab values for indices 1, 5, 3 and 7 
    local id1 = array1[1]
    local id2 = array1[5]
    local id3 = array1[3]
    local id4 = array1[7]
     
    -- filter each value exclusively from the array 
    array1 = CC_ArrayFilter2(array1, id1, ArrayFilterExclusiveType)
    array1 = CC_ArrayFilter2(array1, id2, ArrayFilterExclusiveType)
    array1 = CC_ArrayFilter2(array1, id3, ArrayFilterExclusiveType)
    array1 = CC_ArrayFilter2(array1, id4, ArrayFilterExclusiveType)
     
    Log('-----')
    Log(array1) -- log the filtered array
    Log('---------------------')
     
    -- filter array2
    Log('---- Array2 ----')
    Log(array2) -- log the unfiltered array
    
    -- grab values for indices 1, 5, 3 and 7
    local id1 = array2[1]
    local id2 = array2[5]
    local id3 = array2[3]
    local id4 = array2[7]
    
    -- filter each value exclusively from the array 
    array2 = CC_ArrayFilter2(array2, id1, ArrayFilterExclusiveType)
    array2 = CC_ArrayFilter2(array2, id2, ArrayFilterExclusiveType)
    array2 = CC_ArrayFilter2(array2, id3, ArrayFilterExclusiveType)
    array2 = CC_ArrayFilter2(array2, id4, ArrayFilterExclusiveType)
     
    Log('-----')
    Log(array2) -- log the filtered array
    Log('---------------------')
     
    -- test error with unsupported filter type
    array2 = CC_ArrayFilter2(array2, id1, ArrayFilterGreaterThanType)
    
    • This topic was modified 1 year, 8 months ago by pshai.
    • This topic was modified 1 year, 8 months ago by pshai. Reason: added comments to CC
    • This topic was modified 1 year, 8 months ago by pshai.
    HaasScript Code
    Sign in or Register to download for free
Login or Register to Comment

Unlock your crypto trading potential

Create a free account and enjoy everything we have to offer.

Join for Free