list.jamo (built in)

list: finding, putting in and taking out items of int and string arrays. use "list.jamo"

Sorting ints and strings, and turning arrays around, are in text.jamo: sort_ints, sort_strings, reverse_ints and reverse_strings. The _int and _string versions came first. The ones at the end work on every kind of array, using generics, and sort_by, sort_by_float and sort_by_text sort any array by a key you give each item. sort_with, filtered and mapped take a function of your own.

funclist_check_place

func list_check_place(at: int, count: int, word: string)

funcindex_of_int

func index_of_int(items: [int], value: int): int

Where value first is in items, counting from 0, or -1 when it isn't there

funcindex_of_string

func index_of_string(items: [string], value: string): int

funccontains_int

func contains_int(items: [int], value: int): bool

funccontains_string

func contains_string(items: [string], value: string): bool

funcinsert_int

func insert_int(items: [int], at: int, value: int)

Puts value at place at, moving the items from there on along by one. at can be len(items), to add at the end

funcinsert_string

func insert_string(items: [string], at: int, value: string)

funcremove_int

func remove_int(items: [int], at: int): int

Takes out the item at place at, moving the ones after it back by one, and gives it back

funcremove_string

func remove_string(items: [string], at: int): string

funchas_item

func has_item<T>(items: [T], value: T): bool

funcfind_item

func find_item<T>(items: [T], value: T): int

Where the first one equal to value is, or -1

funccount_item

func count_item<T>(items: [T], value: T): int

funcreversed

func reversed<T>(items: [T]): [T]

A new array with the items the other way round. The array itself stays as it was

funcswap_items

func swap_items<T>(items: [T], a: int, b: int)

funclast_item

func last_item<T>(items: [T]): T

funcsort_floats

func sort_floats(items: [float])

Sorts floats from smallest to largest. nan goes wherever it lands

funcsort_by

func sort_by<T>(items: [T], keys: [int])

Sorts items by int keys, smallest first

funcsort_by_float

func sort_by_float<T>(items: [T], keys: [float])

Sorts items by float keys, smallest first

funcsort_by_text

func sort_by_text<T>(items: [T], keys: [string])

Sorts items by text keys, in the same order as sort_strings ("Zoo" before "apple")

funclist_check_keys

func list_check_keys(items: int, keys: int, word: string)

funclist_order_of

func list_order_of<K>(keys: [K]): [int]

The places of keys from smallest to largest, by merging runs that double in size. Equal keys keep their order. K must work with <=, so ints and floats

funclist_text_order_of

func list_text_order_of(keys: [string]): [int]

The same, for text keys

funcsort_with

func sort_with<T>(items: [T], before: func(T, T): bool)

Sorts items so that before(a, b) is true when a should come before b. Items it calls equal, where neither comes before the other, keep their order. before must give the same answer each time for the same two items

func by_score(a: Player, b: Player): bool
    return a.score > b.score
end
sort_with(players, by_score)       # highest score first

funcfiltered

func filtered<T>(items: [T], keep: func(T): bool): [T]

A new array with the items where keep(item) is true, in order

funcmapped

func mapped<T, U>(items: [T], change: func(T): U): [U]

A new array with change(item) for each item, in order

funclist_put_in_order

func list_put_in_order<T>(items: [T], order: [int])

Moves items so items[i] becomes what was at items[order[i]]