Class: Toybox::Lang::Array

Inherits:
Object
  • Object
show all

Overview

Array objects are fixed size, numerically indexed, single dimensional, and take any Objects (including Arrays) as members. Array keys must be Numbers, but Array values may be any type of Object.

Since:

  • 1.0.0

Instance Method Summary collapse

Methods inherited from Object

equals, hashCode, method, weak

Instance Method Details

add(object) ⇒ Toybox::Lang::Array

Add an Object to the end of an Array.

When adding an Object, the Array size is increased by one and the new Object is inserted at the new index.

Parameters:

Returns:

Since:

  • 1.3.0


6938
6939
# File 'Monkeybrains.rb', line 6938

def add(object)
end

addAll(array) ⇒ Toybox::Lang::Array

Add an Array of Objects to the end of an Array.

When adding an Array of Objects, the Array is expanded by the size of the provided Array, and all of the new elements are inserted starting at the new index.

Parameters:

Returns:

Since:

  • 1.3.0


6950
6951
# File 'Monkeybrains.rb', line 6950

def addAll(array)
end

indexOf(object) ⇒ Toybox::Lang::Number

Get the index of an Object within the Array. Object in the Array. If the Object is not found, -1 is returned.

Parameters:

Returns:

Since:

  • 1.3.0


6958
6959
# File 'Monkeybrains.rb', line 6958

def indexOf(object)
end

remove(object) ⇒ Toybox::Lang::Boolean

Remove an Object from an Array.

If the passed Object is found, the Array size is decreased by one and elements beyond it are shifted to the next lower index. If the Array has multiple matches, the matching Object at the lowest index will be removed but the other matching Objects will not be removed.

If no Object is given as an argument, the Array will remain unchanged and remove() will return false.

Parameters:

Returns:

Since:

  • 1.3.0


6975
6976
# File 'Monkeybrains.rb', line 6975

def remove(object)
end

removeAll(object) ⇒ Toybox::Lang::Boolean

Remove Objects from an Array.

For each instance of the Object that is found, the Array size is decreased by one and elements beyond it are shifted to the next lower index.

If no Object is given as an argument, the Array will remain unchanged and removeAll() will return false.

Parameters:

Returns:

Since:

  • 1.3.0


6991
6992
# File 'Monkeybrains.rb', line 6991

def removeAll(object)
end

reverseToybox::Lang::Array

Return a new Array that contains the elements of a source Array in reverse order.

Returns:

Since:

  • 1.3.0


6998
6999
# File 'Monkeybrains.rb', line 6998

def reverse()
end

sizeToybox::Lang::Number

Get the size of an Array.

Returns:

Since:

  • 1.0.0


7004
7005
# File 'Monkeybrains.rb', line 7004

def size()
end

slice(startIndex, endIndex) ⇒ Toybox::Lang::Array

Get a new Array containing a portion of an existing Array.

Examples:

var myArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

// Get the first five elements of the Array
var newArray1 = myArray.slice(0, 5);     // [1, 2, 3, 4, 5]

// Get the last element of the Array
var newArray2 = myArray.slice(-1, null); // [10]

// Slice off the first and last elements from the Array
var myArray3 = myArray.slice(1, -1);     // [2, 3, 4, 5, 6, 7, 8, 9]

Parameters:

  • startIndex (Toybox::Lang::Number)

    A zero-based index of the start of the new Array. If a negative startIndex is provided, it will offset from the end of the Array. If the startIndex is null, the slice will begin at 0. An out-of-bounds index will be truncated to the array limits.

  • endIndex (Toybox::Lang::Number)

    A zero-based index of the end of the new Array. Items are included up to, but not including endIndex. If a negative endIndex is provided, it will offset from the end of the Array. If endIndex is null, the the slice will end at the last element. An out-of-bounds index will be truncated to the Array limits.

Returns:

Since:

  • 1.3.0


7032
7033
# File 'Monkeybrains.rb', line 7032

def slice(startIndex, endIndex)
end

toStringToybox::Lang::String

Convert an Array to a String.

This does not convert the elements of the Array into Strings, but transforms the entire Array into a String.

Examples:

using Toybox.System;
var myArray = [1, 2, 3, 4, 5];
System.println(myArray[1]);                // prints 1

var myString = myArray.toString();
System.println(myString);                  // "[1, 2, 3, 4, 5]"
System.println(myString[1]);               // UnexpectedTypeException
System.println(myString.substring(0, 5));  // "[1, 2"

Returns:

Since:

  • 1.0.0


7050
7051
# File 'Monkeybrains.rb', line 7050

def toString()
end