Difference between revisions of "Array class"

From Catglobe Wiki
Jump to: navigation, search
(Created page with "<p style="color:#000099; font-size:14px;"><strong>Array : The array object</strong></p> <p>  </p> <p> <span style="color:#a52a2a;"><strong>Constructors</strong></span></p>...")
 
Line 1: Line 1:
<p style="color:#000099; font-size:14px;"><strong>Array : The array object</strong></p>
+
'''Array&nbsp;: The array object'''
<p>
 
&nbsp;</p>
 
<p>
 
<span style="color:#a52a2a;"><strong>Constructors</strong></span></p>
 
<ul>
 
<li style="color:#000000;">
 
<span style="color:#000000;"><strong>() </strong>- Creates an empty array.</span></li>
 
<li style="color:#000000;">
 
<span style="color:#000000;"><strong>(number count)</strong> - Creates an array with a predefined size, where all elements are Empty. Count is a number type, it is number of items to put in the array.</span></li>
 
</ul>
 
<p>
 
&nbsp;</p>
 
<p>
 
<span style="color:#a52a2a;"><strong>Methods</strong></span></p>
 
<ul>
 
<li style="color:#000000;">
 
<span style="color:#000000;"><strong>Empty Add(AnyType element)</strong> - Add a new element to the Array.</span></li>
 
<li style="color:#000000;">
 
<span style="color:#000000;"><strong>number Frequency(number Number)</strong> - Counts the number of times a given Number object exists in the Array. Can only use if all the elements are of type number. Number is the number to search for.</span></li>
 
<li style="color:#000000;">
 
<span style="color:#000000;"><strong>bool IsCharacterArray()</strong> - Check if array is an array of characters.</span></li>
 
<li style="color:#000000;">
 
<span style="color:#000000;"><strong>bool IsNumericArray()</strong> - Check if array is an array of numbers.</span></li>
 
<li style="color:#000000;">
 
<span style="color:#000000;"><strong>bool IsNumericArray()</strong> - Check if array is an array of integer numbers.</span></li>
 
<li style="color:#000000;">
 
<span style="color:#000000;"><strong>bool IsStringArray()</strong> - Check if array is an array of string.</span></li>
 
<li style="color:#000000;">
 
<span style="color:#000000;"><strong>Empty set_Item(number index, AnyType value)</strong> - Set element value at index.</span></li>
 
<li style="color:#000000;">
 
<span style="color:#000000;"><strong>AnyType get_Item(number index)</strong> - Get element at index.</span></li>
 
<li style="color:#000000;">
 
<span style="color:#000000;"><strong>Empty RemoveItemAt(number index)</strong> - Remove an element from the Array. index is the index to remove the object from.</span></li>
 
<li style="color:#000000;">
 
<span style="color:#000000;"><strong>string ToString()</strong> - The string representation of the object.</span></li>
 
<li style="color:#000000;">
 
<span style="color:#000000;"><strong>array Select(Function selector)</strong> - Projects each element of a sequence into a new form. selector is a transform function to apply to each element.</span></li>
 
<li style="color:#000000;">
 
<span style="color:#000000;"><strong>array Where(Function predicate)</strong> - Filters a sequence of values based on a predicate. predicate is a function that takes 1 parameter of the types in the array and return true/false.</span></li>
 
<li style="color:#000000;">
 
<span style="color:#000000;"><strong>array OrderBy(Function comparer)</strong> - Sorts the elements of a sequence in ascending order by using a specified comparer. comparer is a Function that compares two objects of the same type. Must return a signed integer that indicates the relative values of first param A and second param B. Value Less than 0 : A is less than B.Value 0 : A equals B.Value Greater than 0 : A is greater than B.</span></li>
 
<li style="color:#000000;">
 
<span style="color:#000000;"><strong>AnyType First(Function selector)</strong> - Returns the first element in a sequence that satisfies a specified condition. selector is a function to test each element for a condition.</span></li>
 
<li style="color:#000000;">
 
<span style="color:#000000;"><strong>AnyType FirstOrDefault(Function selector)</strong> - Returns the first element in a sequence that satisfies a specified condition or empty if not found. selector is a function to test each element for a condition.</span></li>
 
</ul>
 
<p>
 
&nbsp;</p>
 
<p>
 
<span style="color:#a52a2a;"><strong>Properties</strong></span></p>
 
<ul>
 
<li style="color:#000000;">
 
<span style="color:#000000;"><strong>number Average HasGetter</strong>&nbsp; - Average of the objects in the Array object. Can only use if all the elements are of type Number.</span></li>
 
<li style="color:#000000;">
 
<span style="color:#000000;"><strong>number Count HasGetter</strong>&nbsp; - Number of elements in Array.</span></li>
 
<li style="color:#000000;">
 
<span style="color:#000000;"><strong>number Max HasGetter</strong>&nbsp; - Largest of all the objects in the Array object. Can only use if all the elements are of type Number.</span></li>
 
<li style="color:#000000;">
 
<span style="color:#000000;"><strong>number Min HasGetter</strong>&nbsp; - Smallest of all the objects in the Array object. Can only use if all the elements are of type Number.</span></li>
 
<li style="color:#000000;">
 
<span style="color:#000000;"><strong>string ObjectTypeName HasGetter</strong>&nbsp; - The name of the type of object.</span></li>
 
<li style="color:#000000;">
 
<span style="color:#000000;"><strong>number Sum HasGetter</strong>&nbsp; - Sum of all the objects in the Array object. Can only use if all the elements are of type Number.</span></li>
 
<li style="color:#000000;">
 
<span style="color:#000000;"><strong>TypeInformation TypeInformation HasGetter</strong>&nbsp; - Get information about this class.</span></li>
 
</ul>
 
<p>
 
&nbsp;</p>
 
<p>
 
&nbsp;</p>
 
<p>
 
<span style="color:#a52a2a;"><strong>Examples</strong></span></p>
 
<p>
 
&nbsp;</p>
 
<p>
 
array x = new Array();</p>
 
<p>
 
print(x);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:#008000;">&nbsp;//&nbsp;&nbsp; {}</span></p>
 
<p>
 
&nbsp;</p>
 
<p>
 
array x = new Array(10);</p>
 
<p>
 
print(x);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<span style="color:#008000;">//&nbsp;&nbsp; {Empty,Empty,Empty,Empty,Empty,Empty,Empty,Empty,Empty,Empty}</span></p>
 
<p>
 
&nbsp;</p>
 
<p>
 
array x = {10,20,30,40,50,60,70,80,90,100};</p>
 
<p>
 
array y = x</p>
 
<p>
 
.Select(function (number a) { a;})</p>
 
<p>
 
<span style="font-size:10px;"><span style="color: rgb(0, 128, 0);">// .Select(function (string a) { a;})&nbsp; -&gt; will not work: Cannot assign a value of type &#39;Number&#39; to a variable of type &#39;String&#39;</span></span></p>
 
<p>
 
<span style="font-size:10px;"><span style="color: rgb(0, 128, 0);">// .Select(function (array a) { a;})&nbsp; -&gt; will not work: Cannot assign a value of type &#39;Number&#39; to a variable of type &#39;Array&#39;</span></span></p>
 
<p>
 
<span style="font-size:10px;"><span style="color: rgb(0, 128, 0);">// .Select(function (bool a) { a;})&nbsp; -&gt; will not work: Cannot assign a value of type &#39;Number&#39; to a variable of type &#39;Boolean&#39;</span></span></p>
 
<p>
 
<span style="font-size:10px;"><span style="color: rgb(0, 128, 0);">// .Select(function () { a;})&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&gt; will not work: Function called with too many parameters @</span></span></p>
 
<p>
 
.Where(function (number a) {number i = getRandomNumber(0,10)*10; i &gt; 40;});</p>
 
<p>
 
print(y);&nbsp;&nbsp;</p>
 
<p>
 
&nbsp;</p>
 
<p>
 
array x = {10,20,30,40,50,60,70,80,90,100};</p>
 
<p>
 
array y = x</p>
 
<p>
 
.Select(function (number a) { 88888;})</p>
 
<p>
 
.Where(function (number a) {number i = getRandomNumber(0,10)*10; i &gt; 40;});</p>
 
<p>
 
print(y);&nbsp;&nbsp;</p>
 
<p>
 
&nbsp;</p>
 
<p>
 
array x = {10,20,30,40,50,60,70,80,90,100};</p>
 
<p>
 
array y = x</p>
 
<p>
 
.Select(function (number a) { a;})</p>
 
<p>
 
.Where(function (number a) {number i = getRandomNumber(0,10)*10; i &gt; 40;})</p>
 
<p>
 
.OrderBy(function(number a, number b) {if (a&gt;b) 1; else if (a&lt;b) -1; else 0;});</p>
 
<p>
 
<span style="color:#008000;"><span style="font-size: 10px;">// .OrderBy(function(number a, number b){if (a&gt;b) -1; else if (a&lt;b) 1; else 0;});</span></span></p>
 
<p>
 
print(y);&nbsp;</p>
 
<p>
 
&nbsp;</p>
 
<p>
 
array x = {{1,2,3},{4,false,6,7,8},{10,&quot;ab&quot;,{&quot;aaa&quot;,11,true},13,14},{&quot;aa&quot;,&quot;bb&quot;,17},{},{true,88}};</p>
 
<p>
 
array y = x</p>
 
<p>
 
.Select(function (array a) {; a;})</p>
 
<p>
 
.Where(function (array a) {arrayCount(a) &gt; 3;});</p>
 
<p>
 
print(y); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#008000;">&nbsp;&nbsp; //&nbsp;&nbsp;&nbsp;&nbsp; {{4,False,6,7,8},{10,ab,{aaa,11,True},13,14}}</span></p>
 
<p>
 
&nbsp;</p>
 
<p>
 
array y = {20,30,40,50,70,80,90,100};</p>
 
<p>
 
print(y.FirstOrDefault(function (number a) { true; }));&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#008000;">// 20</span></p>
 
<p>
 
print(y.FirstOrDefault(function (number a) { a &gt; 70; }));&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:#008000;">// 80</span></p>
 
<p>
 
print(y.First(function(number a) { true; }));&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#008000;">// 20</span></p>
 
<p>
 
print(y.First(function(number a) { a &gt; 40; }));&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:#008000;">// 50</span></p>
 
<p>
 
&nbsp;</p>
 
<p>
 
&nbsp;</p>
 
<p>
 
&nbsp;</p>
 
  
 +
&nbsp;
 +
 +
<span style="color:#a52a2a;">'''Constructors'''</span>
 +
 +
*<span style="color:#000000;">'''() '''- Creates an empty array.</span>
 +
*<span style="color:#000000;">'''(number count)''' - Creates an array with a predefined size, where all elements are Empty. Count is a number type, it is number of items to put in the array.</span>
 +
 +
<span style="color:#a52a2a;">'''Methods'''</span>
 +
 +
*<span style="color:#000000;">'''Empty Add(AnyType element)''' - Add a new element to the Array.</span>
 +
*<span style="color:#000000;">'''number Frequency(number Number)''' - Counts the number of times a given Number object exists in the Array. Can only use if all the elements are of type number. Number is the number to search for.</span>
 +
*<span style="color:#000000;">'''bool IsCharacterArray()''' - Check if array is an array of characters.</span>
 +
*<span style="color:#000000;">'''bool IsNumericArray()''' - Check if array is an array of numbers.</span>
 +
*<span style="color:#000000;">'''bool IsNumericArray()''' - Check if array is an array of integer numbers.</span>
 +
*<span style="color:#000000;">'''bool IsStringArray()''' - Check if array is an array of string.</span>
 +
*<span style="color:#000000;">'''Empty set_Item(number index, AnyType value)''' - Set element value at index.</span>
 +
*<span style="color:#000000;">'''AnyType get_Item(number index)''' - Get element at index.</span>
 +
*<span style="color:#000000;">'''Empty RemoveItemAt(number index)''' - Remove an element from the Array. index is the index to remove the object from.</span>
 +
*<span style="color:#000000;">'''string ToString()''' - The string representation of the object.</span>
 +
*<span style="color:#000000;">'''array Select(Function selector)''' - Projects each element of a sequence into a new form. selector is a transform function to apply to each element.</span>
 +
*<span style="color:#000000;">'''array Where(Function predicate)''' - Filters a sequence of values based on a predicate. predicate is a function that takes 1 parameter of the types in the array and return true/false.</span>
 +
*<span style="color:#000000;">'''array OrderBy(Function comparer)''' - Sorts the elements of a sequence in ascending order by using a specified comparer. comparer is a Function that compares two objects of the same type. Must return a signed integer that indicates the relative values of first param A and second param B. Value Less than 0&nbsp;: A is less than B.Value 0&nbsp;: A equals B.Value Greater than 0&nbsp;: A is greater than B.</span>
 +
*<span style="color:#000000;">'''AnyType First(Function selector)''' - Returns the first element in a sequence that satisfies a specified condition. selector is a function to test each element for a condition.</span>
 +
*<span style="color:#000000;">'''AnyType FirstOrDefault(Function selector)''' - Returns the first element in a sequence that satisfies a specified condition or empty if not found. selector is a function to test each element for a condition.</span>
 +
 +
<span style="color:#a52a2a;">'''Properties'''</span>
 +
 +
*<span style="color:#000000;">'''number Average HasGetter'''&nbsp; - Average of the objects in the Array object. Can only use if all the elements are of type Number.</span>
 +
*<span style="color:#000000;">'''number Count HasGetter'''&nbsp; - Number of elements in Array.</span>
 +
*<span style="color:#000000;">'''number Max HasGetter'''&nbsp; - Largest of all the objects in the Array object. Can only use if all the elements are of type Number.</span>
 +
*<span style="color:#000000;">'''number Min HasGetter'''&nbsp; - Smallest of all the objects in the Array object. Can only use if all the elements are of type Number.</span>
 +
*<span style="color:#000000;">'''string ObjectTypeName HasGetter'''&nbsp; - The name of the type of object.</span>
 +
*<span style="color:#000000;">'''number Sum HasGetter'''&nbsp; - Sum of all the objects in the Array object. Can only use if all the elements are of type Number.</span>
 +
*<span style="color:#000000;">'''TypeInformation TypeInformation HasGetter'''&nbsp; - Get information about this class.</span>
 +
 +
&nbsp;
 +
 +
<span style="color:#a52a2a;">'''Examples'''</span>
 +
 +
&nbsp;
 +
 +
array x = new Array();
 +
 +
print(x);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:#008000;">&nbsp;//&nbsp;&nbsp; {}</span>
 +
 +
&nbsp;
 +
 +
array x = new Array(10);
 +
 +
print(x);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<span style="color:#008000;">//&nbsp;&nbsp; {Empty,Empty,Empty,Empty,Empty,Empty,Empty,Empty,Empty,Empty}</span>
 +
 +
&nbsp;
 +
 +
array x = {10,20,30,40,50,60,70,80,90,100};
 +
 +
array y = x
 +
 +
.Select(function (number a) { a;})
 +
 +
<span style="font-size:10px;"><span style="color: rgb(0, 128, 0);">// .Select(function (string a) { a;})&nbsp; -&gt; will not work: Cannot assign a value of type 'Number' to a variable of type 'String'</span></span>
 +
 +
<span style="font-size:10px;"><span style="color: rgb(0, 128, 0);">// .Select(function (array a) { a;})&nbsp; -&gt; will not work: Cannot assign a value of type 'Number' to a variable of type 'Array'</span></span>
 +
 +
<span style="font-size:10px;"><span style="color: rgb(0, 128, 0);">// .Select(function (bool a) { a;})&nbsp; -&gt; will not work: Cannot assign a value of type 'Number' to a variable of type 'Boolean'</span></span>
 +
 +
<span style="font-size:10px;"><span style="color: rgb(0, 128, 0);">// .Select(function () { a;})&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&gt; will not work: Function called with too many parameters @</span></span>
 +
 +
.Where(function (number a) {number i = getRandomNumber(0,10)*10; i &gt; 40;});
 +
 +
print(y);&nbsp;&nbsp;
 +
 +
&nbsp;
 +
 +
array x = {10,20,30,40,50,60,70,80,90,100};
 +
 +
array y = x
 +
 +
.Select(function (number a) { 88888;})
 +
 +
.Where(function (number a) {number i = getRandomNumber(0,10)*10; i &gt; 40;});
 +
 +
print(y);&nbsp;&nbsp;
 +
 +
&nbsp;
 +
 +
array x = {10,20,30,40,50,60,70,80,90,100};
 +
 +
array y = x
 +
 +
.Select(function (number a) { a;})
 +
 +
.Where(function (number a) {number i = getRandomNumber(0,10)*10; i &gt; 40;})
 +
 +
.OrderBy(function(number a, number b) {if (a&gt;b) 1; else if (a&lt;b) -1; else 0;});
 +
 +
<span style="color:#008000;"><span style="font-size: 10px;">// .OrderBy(function(number a, number b){if (a&gt;b) -1; else if (a&lt;b) 1; else 0;});</span></span>
 +
 +
print(y);&nbsp;
 +
 +
&nbsp;
 +
 +
array x = {{1,2,3},{4,false,6,7,8},{10,&quot;ab&quot;,{&quot;aaa&quot;,11,true},13,14},{&quot;aa&quot;,&quot;bb&quot;,17},{},{true,88}};
 +
 +
array y = x
 +
 +
.Select(function (array a) {; a;})
 +
 +
.Where(function (array a) {arrayCount(a) &gt; 3;});
 +
 +
print(y); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#008000;">&nbsp;&nbsp; //&nbsp;&nbsp;&nbsp;&nbsp; {{4,False,6,7,8},{10,ab,{aaa,11,True},13,14}}</span>
 +
 +
&nbsp;
 +
 +
array y = {20,30,40,50,70,80,90,100};
 +
 +
print(y.FirstOrDefault(function (number a) { true; }));&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#008000;">// 20</span>
 +
 +
print(y.FirstOrDefault(function (number a) { a &gt; 70; }));&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:#008000;">// 80</span>
 +
 +
print(y.First(function(number a) { true; }));&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#008000;">// 20</span>
 +
 +
print(y.First(function(number a) { a &gt; 40; }));&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:#008000;">// 50</span>
 +
 +
&nbsp;
 +
 +
&nbsp;
 +
 +
&nbsp;
  
 
[[Category:Data_Types_Literals_and_Variables]]
 
[[Category:Data_Types_Literals_and_Variables]]

Revision as of 04:40, 14 September 2011

Array : The array object

 

Constructors

  • () - Creates an empty array.
  • (number count) - Creates an array with a predefined size, where all elements are Empty. Count is a number type, it is number of items to put in the array.

Methods

  • Empty Add(AnyType element) - Add a new element to the Array.
  • number Frequency(number Number) - Counts the number of times a given Number object exists in the Array. Can only use if all the elements are of type number. Number is the number to search for.
  • bool IsCharacterArray() - Check if array is an array of characters.
  • bool IsNumericArray() - Check if array is an array of numbers.
  • bool IsNumericArray() - Check if array is an array of integer numbers.
  • bool IsStringArray() - Check if array is an array of string.
  • Empty set_Item(number index, AnyType value) - Set element value at index.
  • AnyType get_Item(number index) - Get element at index.
  • Empty RemoveItemAt(number index) - Remove an element from the Array. index is the index to remove the object from.
  • string ToString() - The string representation of the object.
  • array Select(Function selector) - Projects each element of a sequence into a new form. selector is a transform function to apply to each element.
  • array Where(Function predicate) - Filters a sequence of values based on a predicate. predicate is a function that takes 1 parameter of the types in the array and return true/false.
  • array OrderBy(Function comparer) - Sorts the elements of a sequence in ascending order by using a specified comparer. comparer is a Function that compares two objects of the same type. Must return a signed integer that indicates the relative values of first param A and second param B. Value Less than 0 : A is less than B.Value 0 : A equals B.Value Greater than 0 : A is greater than B.
  • AnyType First(Function selector) - Returns the first element in a sequence that satisfies a specified condition. selector is a function to test each element for a condition.
  • AnyType FirstOrDefault(Function selector) - Returns the first element in a sequence that satisfies a specified condition or empty if not found. selector is a function to test each element for a condition.

Properties

  • number Average HasGetter  - Average of the objects in the Array object. Can only use if all the elements are of type Number.
  • number Count HasGetter  - Number of elements in Array.
  • number Max HasGetter  - Largest of all the objects in the Array object. Can only use if all the elements are of type Number.
  • number Min HasGetter  - Smallest of all the objects in the Array object. Can only use if all the elements are of type Number.
  • string ObjectTypeName HasGetter  - The name of the type of object.
  • number Sum HasGetter  - Sum of all the objects in the Array object. Can only use if all the elements are of type Number.
  • TypeInformation TypeInformation HasGetter  - Get information about this class.

 

Examples

 

array x = new Array();

print(x);                                //   {}

 

array x = new Array(10);

print(x);                                //   {Empty,Empty,Empty,Empty,Empty,Empty,Empty,Empty,Empty,Empty}

 

array x = {10,20,30,40,50,60,70,80,90,100};

array y = x

.Select(function (number a) { a;})

// .Select(function (string a) { a;})  -> will not work: Cannot assign a value of type 'Number' to a variable of type 'String'

// .Select(function (array a) { a;})  -> will not work: Cannot assign a value of type 'Number' to a variable of type 'Array'

// .Select(function (bool a) { a;})  -> will not work: Cannot assign a value of type 'Number' to a variable of type 'Boolean'

// .Select(function () { a;})       -> will not work: Function called with too many parameters @

.Where(function (number a) {number i = getRandomNumber(0,10)*10; i > 40;});

print(y);  

 

array x = {10,20,30,40,50,60,70,80,90,100};

array y = x

.Select(function (number a) { 88888;})

.Where(function (number a) {number i = getRandomNumber(0,10)*10; i > 40;});

print(y);  

 

array x = {10,20,30,40,50,60,70,80,90,100};

array y = x

.Select(function (number a) { a;})

.Where(function (number a) {number i = getRandomNumber(0,10)*10; i > 40;})

.OrderBy(function(number a, number b) {if (a>b) 1; else if (a<b) -1; else 0;});

// .OrderBy(function(number a, number b){if (a>b) -1; else if (a<b) 1; else 0;});

print(y); 

 

array x = {{1,2,3},{4,false,6,7,8},{10,"ab",{"aaa",11,true},13,14},{"aa","bb",17},{},{true,88}};

array y = x

.Select(function (array a) {; a;})

.Where(function (array a) {arrayCount(a) > 3;});

print(y);                               //     {{4,False,6,7,8},{10,ab,{aaa,11,True},13,14}}

 

array y = {20,30,40,50,70,80,90,100};

print(y.FirstOrDefault(function (number a) { true; }));                                 // 20

print(y.FirstOrDefault(function (number a) { a > 70; }));                             // 80

print(y.First(function(number a) { true; }));                                               // 20

print(y.First(function(number a) { a > 40; }));                                           // 50