[pshaiCmd] ArrayFilter2

0 254 Views No Comments 10 months 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 9 months, 3 weeks ago by pshai.
    • This topic was modified 9 months, 3 weeks ago by pshai. Reason: added comments to CC
    • This topic was modified 9 months, 3 weeks ago by pshai.
    HaasScript Code
    Sign in or Register to download for free
  • Earn Up to 2,000 $BMEX Tokens Promotion Type: contest Expires: July 31, 2023 Exclusive
    Fire up your trade bots and earn up to 2,000 $BMEX, $BTC, free subscriptions, and more.
Login or Register to Comment

Unlock your crypto trading potential

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

Join for Free