|
|
Line 1: |
Line 1: |
− | {{CGscriptClass_Template|Name=<nowiki>Array</nowiki>|Description=<nowiki>The array object</nowiki>|Constructors={{CGscriptConstructors_Template|Description=<nowiki>Creates an empty array</nowiki>}} | + | {{CGscriptClass_Template|Methods={{CGscriptMethods_Template|ReturnType=array|Name=<nowiki>OrderBy</nowiki>|Parameters={{CGscriptParameters_Template|Type=Function|Name=<nowiki>comparer</nowiki>|Description=<nowiki>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.</nowiki>}} |
− | {{CGscriptConstructors_Template|Parameters=
| + | |Description=<nowiki>Sorts the elements of a sequence in ascending order by using a specified comparer.</nowiki>}}}} |
− | {{CGscriptParameters_Template|Type=number|Name=<nowiki>count</nowiki>|Description=<nowiki>Number of items to put in the array</nowiki>}}
| |
− | |Description=<nowiki>Creates an array with a predefined size, where all elements are Empty</nowiki>}}|Methods=
| |
− | {{CGscriptMethods_Template|ReturnType=Empty|Name=<nowiki>Add</nowiki>|Parameters=
| |
− | {{CGscriptParameters_Template|Type=AnyType|Name=<nowiki>element</nowiki>|Description=<nowiki>element to add</nowiki>}}
| |
− | |Description=<nowiki>Add a new element to the Array</nowiki>}}
| |
− | {{CGscriptMethods_Template|ReturnType=AnyType|Name=<nowiki>First</nowiki>|Parameters=
| |
− | {{CGscriptParameters_Template|Type=Function|Name=<nowiki>selector</nowiki>|Description=<nowiki>A function to test each element for a condition.</nowiki>}}
| |
− | |Description=<nowiki>Returns the first element in a sequence that satisfies a specified condition.</nowiki>}}
| |
− | {{CGscriptMethods_Template|ReturnType=AnyType|Name=<nowiki>FirstOrDefault</nowiki>|Parameters=
| |
− | {{CGscriptParameters_Template|Type=Function|Name=<nowiki>selector</nowiki>|Description=<nowiki>A function to test each element for a condition.</nowiki>}}
| |
− | |Description=<nowiki>Returns the first element in a sequence that satisfies a specified condition or empty if not found.</nowiki>}}
| |
− | {{CGscriptMethods_Template|ReturnType=number|Name=<nowiki>Frequency</nowiki>|Parameters=
| |
− | {{CGscriptParameters_Template|Type=number|Name=<nowiki>number</nowiki>|Description=<nowiki>The number to search for</nowiki>}}
| |
− | |Description=<nowiki>Counts the number of times a given Number object exists in the Array. Can only use if all the elements are of type Number</nowiki>}}
| |
− | {{CGscriptMethods_Template|ReturnType=AnyType|Name=<nowiki>this[] { get; }</nowiki>|Parameters=
| |
− | {{CGscriptParameters_Template|Type=number|Name=<nowiki>index</nowiki>|Description=<nowiki>Index</nowiki>}}
| |
− | |Description=<nowiki>Get element at index</nowiki>}}
| |
− | {{CGscriptMethods_Template|ReturnType=bool|Name=<nowiki>IsCharacterArray</nowiki>|Description=<nowiki>check if array is an array of characters</nowiki>}}
| |
− | {{CGscriptMethods_Template|ReturnType=bool|Name=<nowiki>IsNumericArray</nowiki>|Description=<nowiki>check if array is an array of numbers</nowiki>}}
| |
− | {{CGscriptMethods_Template|ReturnType=bool|Name=<nowiki>IsNumericArray</nowiki>|Description=<nowiki>check if array is an array of integer numbers</nowiki>}}
| |
− | {{CGscriptMethods_Template|ReturnType=bool|Name=<nowiki>IsStringArray</nowiki>|Description=<nowiki>check if array is an array of string</nowiki>}}
| |
− | {{CGscriptMethods_Template|ReturnType=array|Name=<nowiki>OrderBy</nowiki>|Parameters= | |
− | {{CGscriptParameters_Template|Type=Function|Name=<nowiki>comparer</nowiki>|Description=<nowiki>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.</nowiki>}} | |
− | |Description=<nowiki>Sorts the elements of a sequence in ascending order by using a specified comparer.</nowiki>}} | |
− | {{CGscriptMethods_Template|ReturnType=Empty|Name=<nowiki>RemoveItemAt</nowiki>|Parameters=
| |
− | {{CGscriptParameters_Template|Type=number|Name=<nowiki>index</nowiki>|Description=<nowiki>The index to remove the object from</nowiki>}}
| |
− | |Description=<nowiki>Remove an element from the Array</nowiki>}}
| |
− | {{CGscriptMethods_Template|ReturnType=array|Name=<nowiki>Select</nowiki>|Parameters=
| |
− | {{CGscriptParameters_Template|Type=Function|Name=<nowiki>selector</nowiki>|Description=<nowiki>A transform function to apply to each element.</nowiki>}}
| |
− | |Description=<nowiki>Projects each element of a sequence into a new form.</nowiki>}}
| |
− | {{CGscriptMethods_Template|ReturnType=Empty|Name=<nowiki>this[] { set; }</nowiki>|Parameters=
| |
− | {{CGscriptParameters_Template|Type=number|Name=<nowiki>index</nowiki>|Description=<nowiki>Index</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=AnyType|Name=<nowiki>value</nowiki>|Description=<nowiki>Value to set</nowiki>}}
| |
− | |Description=<nowiki>Set element value at index</nowiki>}}
| |
− | {{CGscriptMethods_Template|ReturnType=string|Name=<nowiki>ToString</nowiki>|Description=<nowiki>The string representation of the object.</nowiki>}}
| |
− | {{CGscriptMethods_Template|ReturnType=array|Name=<nowiki>Where</nowiki>|Parameters=
| |
− | {{CGscriptParameters_Template|Type=Function|Name=<nowiki>predicate</nowiki>|Description=<nowiki>A function that takes 1 parameter of the types in the array and return true/false</nowiki>}}
| |
− | |Description=<nowiki>Filters a sequence of values based on a predicate.</nowiki>}}
| |
− | |Properties=
| |
− | {{CGscriptProperties_Template|ReturnType=number|Name=<nowiki>Average</nowiki>|HasGetter=1|Description=<nowiki>Average of the objects in the Array object. Can only use if all the elements are of type Number</nowiki>}}
| |
− | {{CGscriptProperties_Template|ReturnType=number|Name=<nowiki>Count</nowiki>|HasGetter=1|Description=<nowiki>Number of elements in Array</nowiki>}}
| |
− | {{CGscriptProperties_Template|ReturnType=number|Name=<nowiki>Max</nowiki>|HasGetter=1|Description=<nowiki>Largest of all the objects in the Array object. Can only use if all the elements are of type Number</nowiki>}}
| |
− | {{CGscriptProperties_Template|ReturnType=number|Name=<nowiki>Min</nowiki>|HasGetter=1|Description=<nowiki>Smallest of all the objects in the Array object. Can only use if all the elements are of type Number</nowiki>}}
| |
− | {{CGscriptProperties_Template|ReturnType=string|Name=<nowiki>ObjectTypeName</nowiki>|HasGetter=1|Description=<nowiki>The name of the type of object.</nowiki>}}
| |
− | {{CGscriptProperties_Template|ReturnType=number|Name=<nowiki>Sum</nowiki>|HasGetter=1|Description=<nowiki>Sum of all the objects in the Array object. Can only use if all the elements are of type Number</nowiki>}}
| |
− | {{CGscriptProperties_Template|ReturnType=TypeInformation|Name=<nowiki>TypeInformation</nowiki>|HasGetter=1|Description=<nowiki>Get information about this class.</nowiki>}}
| |
− | }} | |
− | | |
− | <br>
| |
− | | |
− | ==== <span style="color:#a52a2a;">'''Examples'''</span> ====
| |
− | | |
− | <source lang="javascript">array x = new Array();
| |
− | print(x); // {}</source><br> <source lang="javascript">array x = new Array(10);
| |
− | print(x); // {Empty,Empty,Empty,Empty,Empty,Empty,Empty,Empty,Empty,Empty}</source><br> <source lang="javascript">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);</source><br> <source lang="javascript">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);</source><br> <source lang="javascript">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);</source><br> <source lang="javascript">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}}</source><br> <source lang="javascript">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</source>
| |
− | | |
− | [[Category:Data_Types_Literals_and_Variables]]
| |