Array class: Difference between revisions
More actions
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
== ArrayΒ == | |||
The array object <br> | |||
<br>'''Constructors'''<br> | |||
<br>β’ () - Creates an empty array<br>β’ (number count "Number of items to put in the array") - Creates an array with a predefined size, where all elements are Empty<br> Β | |||
<br> | <br>'''Methods'''<br> Β | ||
<br>β’ Empty Add(AnyType element "element to add") - Add a new element to the Array<br>β’ AnyType First(Function selector "A function to test each element for a condition.") - Returns the first element in a sequence that satisfies a specified condition.<br>β’ AnyType FirstOrDefault(Function selector "A function to test each element for a condition.") - Returns the first element in a sequence that satisfies a specified condition or empty if not found.<br>β’ number Frequency(number number "The number to search for") - Counts the number of times a given Number object exists in the Array. Can only use if all the elements are of type Number<br>β’ AnyType this[] { get; }(number index "Index") - Get element at index<br>β’ bool IsCharacterArray() - check if array is an array of characters<br>β’ bool IsNumericArray() - check if array is an array of numbers<br>β’ bool IsNumericArray() - check if array is an array of integer numbers<br>β’ bool IsStringArray() - check if array is an array of string<br>β’ array OrderBy(Function comparer "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.") - Sorts the elements of a sequence in ascending order by using a specified comparer.<br>β’ Empty RemoveItemAt(number index "The index to remove the object from") - Remove an element from the Array<br>β’ array Select(Function selector "A transform function to apply to each element.") - Projects each element of a sequence into a new form.<br>β’ Empty this[] { set; }(number index "Index", AnyType value "Value to set") - Set element value at index<br>β’ string ToString() - The string representation of the object.<br>β’ array Where(Function predicate "A function that takes 1 parameter of the types in the array and return true/false") - Filters a sequence of values based on a predicate.<br> Β | |||
<br> | <br>'''Properties'''<br> Β | ||
<br> Β | |||
<br> | β’ number Average { get; } - Average of the objects in the Array object. Can only use if all the elements are of type Number<br>β’ number Count { get; } - Number of elements in Array<br>β’ number Max { get; } - Largest of all the objects in the Array object. Can only use if all the elements are of type Number<br>β’ number Min { get; } - Smallest of all the objects in the Array object. Can only use if all the elements are of type Number<br>β’ string ObjectTypeName { get; } - The name of the type of object.<br>β’ number Sum { get; } - Sum of all the objects in the Array object. Can only use if all the elements are of type Number<br>β’ TypeInformation TypeInformation { get; } - Get information about this class.<br> Β | ||
<br> Β | |||
<br> | '''Examples '''<br> Β | ||
= | <br>1. array x = new Array();<br>2. print(x); // {} | ||
1. array x = new Array(10);<br>2. print(x); // {Empty,Empty,Empty,Empty,Empty,Empty,Empty,Empty,Empty,Empty} Β | |||
1. array x = | 1. array x = {10,20,30,40,50,60,70,80,90,100};<br>2. array y = x<br>3. .Select(function (number a) { a;})<br>4. // .Select(function (string a) { a;}) -> will not work: Cannot assign a value of type 'Number' to a variable of type 'String'<br>5. // .Select(function (array a) { a;}) -> will not work: Cannot assign a value of type 'Number' to a variable of type 'Array'<br>6. // .Select(function (bool a) { a;}) -> will not work: Cannot assign a value of type 'Number' to a variable of type 'Boolean'<br>7. // .Select(function () { a;}) -> will not work: Function called with too many parameters @<br>8. .Where(function (number a) {number i = getRandomNumber(0,10)*10; i > 40;});<br>9. print(y); | ||
1. array x = {10,20,30,40,50,60,70,80,90,100};<br>2. array y = x<br>3. .Select(function (number a) { | 1. array x = {10,20,30,40,50,60,70,80,90,100};<br>2. array y = x<br>3. .Select(function (number a) { 88888;})<br>4. .Where(function (number a) {number i = getRandomNumber(0,10)*10; i > 40;});<br>5. print(y); Β | ||
1. array x = {10,20,30,40,50,60,70,80,90,100};<br>2. array y = x<br>3. .Select(function (number a) { | 1. array x = {10,20,30,40,50,60,70,80,90,100};<br>2. array y = x<br>3. .Select(function (number a) { a;})<br>4. .Where(function (number a) {number i = getRandomNumber(0,10)*10; i > 40;})<br>5. .OrderBy(function(number a, number b) {if (a>b) 1; else if (a<b) -1; else 0;});<br>6. // .OrderBy(function(number a, number b){if (a>b) -1; else if (a<b) 1; else 0;});<br>7. print(y);<br><br> | ||
<br> Β | |||
<br> | <br><br> Β | ||
[[Category:Classes]] | |||
Revision as of 02:58, 12 March 2013
Array
The array object
Constructors
β’ () - Creates an empty array
β’ (number count "Number of items to put in the array") - Creates an array with a predefined size, where all elements are Empty
Methods
β’ Empty Add(AnyType element "element to add") - Add a new element to the Array
β’ AnyType First(Function selector "A function to test each element for a condition.") - Returns the first element in a sequence that satisfies a specified condition.
β’ AnyType FirstOrDefault(Function selector "A function to test each element for a condition.") - Returns the first element in a sequence that satisfies a specified condition or empty if not found.
β’ number Frequency(number number "The number to search for") - Counts the number of times a given Number object exists in the Array. Can only use if all the elements are of type Number
β’ AnyType this[] { get; }(number index "Index") - Get element at index
β’ 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
β’ array OrderBy(Function comparer "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.") - Sorts the elements of a sequence in ascending order by using a specified comparer.
β’ Empty RemoveItemAt(number index "The index to remove the object from") - Remove an element from the Array
β’ array Select(Function selector "A transform function to apply to each element.") - Projects each element of a sequence into a new form.
β’ Empty this[] { set; }(number index "Index", AnyType value "Value to set") - Set element value at index
β’ string ToString() - The string representation of the object.
β’ array Where(Function predicate "A function that takes 1 parameter of the types in the array and return true/false") - Filters a sequence of values based on a predicate.
Properties
β’ number Average { get; } - Average of the objects in the Array object. Can only use if all the elements are of type Number
β’ number Count { get; } - Number of elements in Array
β’ number Max { get; } - Largest of all the objects in the Array object. Can only use if all the elements are of type Number
β’ number Min { get; } - Smallest of all the objects in the Array object. Can only use if all the elements are of type Number
β’ string ObjectTypeName { get; } - The name of the type of object.
β’ number Sum { get; } - Sum of all the objects in the Array object. Can only use if all the elements are of type Number
β’ TypeInformation TypeInformation { get; } - Get information about this class.
Examples
1. array x = new Array();
2. print(x); // {}
1. array x = new Array(10);
2. print(x); // {Empty,Empty,Empty,Empty,Empty,Empty,Empty,Empty,Empty,Empty}
1. array x = {10,20,30,40,50,60,70,80,90,100};
2. array y = x
3. .Select(function (number a) { a;})
4. // .Select(function (string a) { a;}) -> will not work: Cannot assign a value of type 'Number' to a variable of type 'String'
5. // .Select(function (array a) { a;}) -> will not work: Cannot assign a value of type 'Number' to a variable of type 'Array'
6. // .Select(function (bool a) { a;}) -> will not work: Cannot assign a value of type 'Number' to a variable of type 'Boolean'
7. // .Select(function () { a;}) -> will not work: Function called with too many parameters @
8. .Where(function (number a) {number i = getRandomNumber(0,10)*10; i > 40;});
9. print(y);
1. array x = {10,20,30,40,50,60,70,80,90,100};
2. array y = x
3. .Select(function (number a) { 88888;})
4. .Where(function (number a) {number i = getRandomNumber(0,10)*10; i > 40;});
5. print(y);
1. array x = {10,20,30,40,50,60,70,80,90,100};
2. array y = x
3. .Select(function (number a) { a;})
4. .Where(function (number a) {number i = getRandomNumber(0,10)*10; i > 40;})
5. .OrderBy(function(number a, number b) {if (a>b) 1; else if (a<b) -1; else 0;});
6. // .OrderBy(function(number a, number b){if (a>b) -1; else if (a<b) 1; else 0;});
7. print(y);