Skip to content

New List Functions

Irtsa edited this page Feb 8, 2025 · 3 revisions

List Functions

These functions extend from the current List object/class from greyscript.

The following are a list of new functions that can be utilized.





max

Will return the largest value in the list.

print([1, 3, 8, 5, 1, 5, 0].max)
-- 8


min

Will return the smallest value in the list.

print([1, 3, 8, 5, 1, 5, 0].min)
-- 0


maxIndex

Will return the index of the largest value in the list.

print([1, 3, 8, 5, 1, 5, 0].maxIndex)
-- 2


minIndex

Will return the index of the smallest value in the list.

print([1, 3, 8, 5, 1, 5, 0].minIndex)
-- 6


hasItem (item)

Will return true if the list contains the item provided, false if otherwise.

print([1, 3, 8, 5, 1, 5, 0].hasItem(8))
-- 1(true)


delete (item)

Will delete the first instance of the given item from list and will also return said list.

newlist = [1, 2, 2, 1, 3]
newlist.delete(1)
print(newlist)
-- [2, 2, 1, 3]


print([1, 2, 2, 1, 3].delete(1))
-- [2, 2, 1, 3]


deleteAll (item

Will delete the all instances of the given item from list and will also return said list.

newlist = [1, 2, 2, 1, 3]
newlist.deleteAll(1)
print(newlist)
-- [2, 2, 3]


print([1, 2, 2, 1, 3].deleteAll(1))
-- [2, 2, 3]


set

Will delete all duplicates from list and will also return said list.

newlist = [1, 2, 2, 1, 3]
newlist.set
print(newlist)
-- [1, 2, 3]


print([1, 2, 2, 1, 3].set)
-- [1, 2, 3]


count (item)

Will return how many times the given item appears in said list.

print([1, 2, 2, 1, 3].count(2))
-- 2


mean

Will return the mean (average) of the said list.

print([1, 3, 8, 5, 1, 5, 0].mean)
-- 3.28571...


median

Will return the smallest value in the list.

print([1, 3, 8, 5, 1, 5, 0].median)
-- 3


mode

Will return the most common value in the list.

print([1, 3, 8, 5, 1, 5, 0].mode)
-- 1


all

Will return true if all values in said list are true.

print([true, true, false].all)
-- 0(false)


any

Will return true if at least one values in said list are true.

print([true, true, false].any)
-- 1(true)


applyFunction (func)

Will apply the given function func onto all items in the given list.

print([1.32, 124.234, 423.3, 32.24545].applyFunction(@floor))
-- [1, 124, 423, 32]

Clone this wiki locally