• My Pages
  • Comments
  • Add Link
  • Subscribe
  • Subscribe User
  • Edit (Text)
  • Rename Page
  • Copy Page
  • Load Page
  • Save Page
  • Delete Page
  • Attachments
  • Check Spelling
  • Diffs
  • Info
  • Revert to this revision
  • XML
  • Render as Docbook
  • Print View
  • Raw Text
  • Delete Cache
  • Like Pages
  • Local Site Map
  • Remove Spam
  • Package Pages
  • Sync Pages
    • Diff for "Arrays"
    Differences between revisions 1 and 9 (spanning 8 versions)
    Revision 1 as of 2014-01-27 11:40:41
    Size: 2999
    Editor: Inanna
    Comment:
    Revision 9 as of 2014-07-29 04:59:28
    Size: 4634
    Editor: LKD70
    Comment:
    Deletions are marked like this. Additions are marked like this.
    Line 1: Line 1:
    The following functions can be used to manipulate and array details from objects and variables.

    These should be written in the following formats:
     .''variable.function(arguments)'', example - ''myVar.subStr(3,2)'' if your variable name was "myVar" and you wanted to use subStr() to find the 2 characters that begin 3 from the left.

     .''object.function(arguments)'', example - ''city.coords.split(",")'' if you wanted to split the coordinates of your city into an array to determine the seperate x and y values using the split() function.
    The following functions can be used to manipulate an array.
    Line 11: Line 6:
    ||<tablewidth="796px" tableheight="123px"#cccccc>'''Function ''' ||<#cccccc>'''Type''' ||<#cccccc>'''Description '''||||<style="text-align:center"> || || ||<tablewidth="796px" tableheight="123px"#cccccc>'''Function ''' ||<#cccccc>'''Type''' ||<#cccccc>'''Description ''' ||||<style="text-align:center"> || ||
    Line 16: Line 11:
    ||[[#concat|concat]] ||array ||Used to join two or more arrays together. ||
    ||[[#sort|sort]] ||array ||Used to sort the order of array elements. ||
    ||[[#join|join]] ||string ||Takes an array and joins the elements into one string. ||
    ||[[#IndexOf|IndexOf]] ||int ||Checks for the first instance of an element and returns its position. ||
    ||[[#lastIndexOf|lastIndexOf]] ||int ||Checks for the last instance of an element and returns its position. ||
    Line 24: Line 25:
     .myArray = ["a","b","c","d"]
     .echo "myArray = "+myArray
     .returnVal = myArray.push("e")
     .echo "myArray = "+myArray
     .echo "returnVal = "+returnVal

    . myArray = ["a","b","c","d"]
     . echo "myArray = "+myArray
     . returnVal = myArray.push("e")
     . echo "myArray = "+myArray
     . echo "returnVal = "+returnVal
    Line 31: Line 33:
     .a,b,c,d
     .a,b,c,d,e
     .5

    . a,b,c,d
     . a,b,c,d,e
     . 5
    Line 41: Line 44:
     .myArray = ["a","b","c","d"]
     .echo "myArray = "+myArray
     .returnVal = myArray.pop()
     .echo "myArray = "+myArray
     .echo "returnVal = "+returnVal

    . myArray = ["a","b","c","d"]
     . echo "myArray = "+myArray
     . returnVal = myArray.pop()
     . echo "myArray = "+myArray
     . echo "returnVal = "+returnVal
    Line 48: Line 52:
     .a,b,c,d
     .a,b,c
     .d
    Line 52: Line 53:
     . a,b,c,d
     . a,b,c
     . d
    Line 59: Line 63:
     .myArray = ["a","b","c","d"]
     .echo "myArray = "+myArray
     .returnVal = myArray.unshift("_")
     .echo "myArray = "+myArray
     .echo "returnVal = "+returnVal

    . myArray = ["a","b","c","d"]
     . echo "myArray = "+myArray
     . returnVal = myArray.unshift("_")
     . echo "myArray = "+myArray
     . echo "returnVal = "+returnVal
    Line 66: Line 71:
     .a,b,c,d
     ._,a,b,c,d
     .5

    . a,b,c,d
     . _,a,b,c,d
     . 5
    Line 76: Line 82:
     .myArray = ["a","b","c","d"]
     .echo "myArray = "+myArray
     .returnVal = myArray.shift()
     .echo "myArray = "+myArray
     .echo "returnVal = "+returnVal

    . myArray = ["a","b","c","d"]
     . echo "myArray = "+myArray
     . returnVal = myArray.shift()
     . echo "myArray = "+myArray
     . echo "returnVal = "+returnVal
    Line 83: Line 90:
     .a,b,c,d
     .b,c,d
     .a

     . a,b,c,d
     . b,c,d
     . a



    = concat =
    '''Usage:''' array.concat()

    used to join two or more arrays together.

    ==== Example: ====
    boy = ["Luke", "Bob","Jason"]

    girl = ["Emma", "Katie", "Chiara"]

    uni = ["Jordan","alex","Jessie"]

    names = uni.concat(girl,boy)

    echo names

    ==== Result: ====
    Jordan,alex,Jessie,Emma,Katie,Chiara,Luke,Bob,Jason


    = sort =
    '''Usage:''' array.sort()

    Used to sort the order of array elements.


    '''Example:'''

     . array = ["b", "a", "d", "c"]
     . echo array.sort()

    '''Result:'''

     . a,b,c,d


    = join =
    '''Usage:''' array.join()

    Takes an array and joins the elements into one string.


    '''Example:'''

     . array = ["a", "b", "c", "d"]
     . echo array.join()

    '''Result:'''

     . "a,b,c,d"



    = IndexOf =
    '''Usage:''' array.indexOf()

    Checks for the first instance of an element and returns its position.

    If the item is not found, it will return as "-1"

    If the item is present more than once, the indexOf method returns the position of the first occurrence.

    '''Example:'''

    array = ["google", "yahoo", "!DuckDuckGo", "Bing"]
    echo array.indexOf("!DuckDuckGo")


    '''Result:'''

     . 2



    = lastIndexOf =
    '''Usage:''' array.lastIndexOf()

    Checks for the last instance of an element and returns its position.

    If the item is not found, it will return as "-1"

    If the item is present more than once, the lastIndexOf method returns the position of the last occurrence.


    '''Example:'''

    array = ["google", "yahoo", "!DuckDuckGo", "Bing","!DuckDuckGo","google"]
    echo array.lastIndexOf("!DuckDuckGo")


    '''Result:'''

     . 4

    The following functions can be used to manipulate an array.

    Click each function name in the table below for more details of it, with examples.

    Functions

    Function

    Type

    Description

    push

    array

    Adds one or more elements to the end of an array and returns the new length of the array.

    pop

    array

    Removes the last element from an array and returns the value of that element.

    unshift

    array

    Adds one or more elements to the beginning of an array and returns the new length of the array. The other elements in the array are moved from their original position, i, to i+1.

    shift

    array

    Removes the first element from an array and returns that element. The remaining array elements are moved from their original position, i, to i-1.

    concat

    array

    Used to join two or more arrays together.

    sort

    array

    Used to sort the order of array elements.

    join

    string

    Takes an array and joins the elements into one string.

    IndexOf

    int

    Checks for the first instance of an element and returns its position.

    lastIndexOf

    int

    Checks for the last instance of an element and returns its position.

    push

    Usage: array.push("x")

    Adds one or more elements to the end of an array and returns the new length of the array.

    Example:

    • myArray = ["a","b","c","d"]
    • echo "myArray = "+myArray
    • returnVal = myArray.push("e")
    • echo "myArray = "+myArray
    • echo "returnVal = "+returnVal

    Result:

    • a,b,c,d
    • a,b,c,d,e
    • 5

    pop

    Usage: array.pop()

    Removes the last element from an array and returns the value of that element.

    Example:

    • myArray = ["a","b","c","d"]
    • echo "myArray = "+myArray
    • returnVal = myArray.pop()
    • echo "myArray = "+myArray
    • echo "returnVal = "+returnVal

    Result:

    • a,b,c,d
    • a,b,c
    • d

    unshift

    Usage: array.unshift("x")

    Adds one or more elements to the beginning of an array and returns the new length of the array. The other elements in the array are moved from their original position, i, to i+1.

    Example:

    • myArray = ["a","b","c","d"]
    • echo "myArray = "+myArray
    • returnVal = myArray.unshift("_")
    • echo "myArray = "+myArray
    • echo "returnVal = "+returnVal

    Result:

    • a,b,c,d
    • _,a,b,c,d
    • 5

    shift

    Usage: array.shift()

    Removes the first element from an array and returns that element. The remaining array elements are moved from their original position, i, to i-1.

    Example:

    • myArray = ["a","b","c","d"]
    • echo "myArray = "+myArray
    • returnVal = myArray.shift()
    • echo "myArray = "+myArray
    • echo "returnVal = "+returnVal

    Result:

    • a,b,c,d
    • b,c,d
    • a

    concat

    Usage: array.concat()

    used to join two or more arrays together.

    Example:

    boy = ["Luke", "Bob","Jason"]

    girl = ["Emma", "Katie", "Chiara"]

    uni = ["Jordan","alex","Jessie"]

    names = uni.concat(girl,boy)

    echo names

    Result:

    Jordan,alex,Jessie,Emma,Katie,Chiara,Luke,Bob,Jason

    sort

    Usage: array.sort()

    Used to sort the order of array elements.

    Example:

    • array = ["b", "a", "d", "c"]
    • echo array.sort()

    Result:

    • a,b,c,d

    join

    Usage: array.join()

    Takes an array and joins the elements into one string.

    Example:

    • array = ["a", "b", "c", "d"]
    • echo array.join()

    Result:

    • "a,b,c,d"

    IndexOf

    Usage: array.indexOf()

    Checks for the first instance of an element and returns its position.

    If the item is not found, it will return as "-1"

    If the item is present more than once, the indexOf method returns the position of the first occurrence.

    Example:

    array = ["google", "yahoo", "DuckDuckGo", "Bing"] echo array.indexOf("DuckDuckGo")

    Result:

    • 2

    lastIndexOf

    Usage: array.lastIndexOf()

    Checks for the last instance of an element and returns its position.

    If the item is not found, it will return as "-1"

    If the item is present more than once, the lastIndexOf method returns the position of the last occurrence.

    Example:

    array = ["google", "yahoo", "DuckDuckGo", "Bing","DuckDuckGo","google"] echo array.lastIndexOf("DuckDuckGo")

    Result:

    • 4


    CategoryFunctions

    Arrays (last edited 2015-04-17 00:19:57 by LKD70)