More Simple Array Commands

Propose new features and changes
User avatar
dangerdogL2121
Posts: 173
Joined: 01 Oct 2013, 23:11

More Simple Array Commands

13 May 2015, 01:53

Simple arrays are already very nice to have, but it seems like there could be a few more commands. By simple arrays I mean "real" arrays and not dynamic variables.
  • A command to check if every item in two arrays are equal - that both arrays are exactly the same.
    From the docs:
    When an object reference is compared with some other value using one of = == != <>, they are considered equal only if both values are references to the same object.
    Objects are always considered true when a boolean value is required, such as in if obj, !obj or obj ? x : y.
    An object's address can be retrieved using the &address-of operator. This uniquely identifies the object from the point of its creation to the moment its last reference is released.
    From what it sounds like, using an object in an if statement only checks to see if both values refer to the same object. An array checking command would be nice.

    Of course, a solution can be made with AutoHotkey:

    Code: Select all

    SameArray(array1, array2)
    {
    Loop, % (%array1%.MaxIndex() > %array2%.MaxIndex) ? %array1%.MaxIndex() : %array2%.MaxIndex()
    {
    if(%array1%[A_Index] != %array2%[A_Index])
    return 0
    }
    return 1
    }
    But an AHK solution would be faster and easier.
  • A command to check if any item in the array contains a string. I did not find anything in the docs that could have been this.
    AHK solution:

    Code: Select all

    ArrayContains(array, searchfor)
    {
    Loop, % %array%.MaxIndex()
    {
    if(%array%[A_Index] = searchfor)
    {
    return 1
    break
    }
    }
    return 0
    }
  • Lastly a command to search and remove a string from and array.
    I could not get a function to return the array with the removed item, so it just returns the position of the item.

    Code: Select all

    ArrayRemove(ByRef array, searchfor)
    {
    index = 0
    Loop, % %array%.MaxIndex()
    {
    if(%array%[A_Index] = searchfor)
    {
    return A_Index
    }
    }
    return 0
    }
Thanks
User avatar
dangerdogL2121
Posts: 173
Joined: 01 Oct 2013, 23:11

Re: More Simple Array Commands

13 May 2015, 02:05

Oh, I see tidbit already posted about arrays.

Return to “Wish List”

Who is online

Users browsing this forum: No registered users and 7 guests