List Functions
List functions helps you to manipulate and work on list with great ease, speed and efficiency. These functions are highly optimized and well-tested.
SRON provides 16 functions for this:
at()
clear()
count()
delete()
index()
insert()
len()
push()
pop()
replace()
reverse()
reverse_sort()
rindex()
sort()
sublist()
update()
1. at():
This function is used to get the 'Char' value at a particular index.
OUTPUT:
2.2
2. clear():
This function empties the whole List.
OUTPUT:
[1, 2.200000, true, [11.110000, Wow]] []
3. count():
This function is used to count occurrence of a value in a List.
OUTPUT:
2
4. delete():
This function is used to delete a value from the List. It takes two arguments: the first argument is of type 'List' from which you have to delete the element and the second argument is of type 'Int' which is for the index from which element is need to be deleted. It returns Void.
OUTPUT:
[1, 2.2, true]
5. index():
This function is used to find the index of first occurrence of a value in a List. Returns -1, if value not found.
OUTPUT:
1
6. insert():
This function is used to insert a value into 'List'. It takes 3 arguments: first of type 'List', second of type 'Int' to specify at what index you want to insert the value, and third is the value you want to insert. It returns Void.
OUTPUT:
[1, 2.2, SRON, true, [11.11, Wow]]
7. len():
This function is used to get the length of the String.
OUTPUT:
4
8. push():
This function is used to append a value to the end of List. It takes two arguments: the List value in which you want to push and another one is a value of any type.
OUTPUT:
[1, 2.2, true, [11.11, Wow], Hi]
9. pop():
This function is used to delete and return the last element of the List. It takes only one argument that is List and returns value of any type.
OUTPUT:
[11.11, Wow] [1, 2.2, true]
10. replace():
This function is used to replace all the occurence of a particular value with another value. It takes three arguments: first is List value, second one is value which will be replaced and third value which will be replacement of second argument. It returns void.
OUTPUT:
[1, 2.2, SRON, [11.11, Wow], SRON]
11. reverse():
This function is used to reverse a String. It takes only String as input and returns Void.
OUTPUT:
[[11.11, Wow], true, 2.2, 1]
12. rindex():
This function is used to get the index of a first value occurrence from the end. It takes two arguments: the List value from which you require to find the value and another argument is a value for which you want to find the index. It returns -1, if the character is not found.
OUTPUT:
4
13. sort():
This function is used to sort a String. It returns a Void value.
OUTPUT:
[1, 2, 3, 4, 5]
14. subpart():
This function is used to extract a part of List. It takes 3 arguments: first is the 'List' from which you will extract the sublist, then the 'Int' index by which you need to start extraction, then another 'Int' index by which you want to end the extraction.
OUTPUT:
[2.2, true]
15. update():
This function is used to update a value at a particular index in a List. It takes 3 arguments: first is the 'List', second is the 'Int' index at which you have to put a new value, and the third argument is the new value at that index.
OUTPUT:
[1, 2.2, true, SRON, true]
16. reverse_sort():
This function is used to sort a String in reverse order. It returns a Void value.
OUTPUT:
[5, 4, 3, 2, 1]
Last updated