JanetDocsI'm feeling luckyGithub sign in

array/slice



    cfunction

    (array/slice arrtup &opt start end)
    
    Takes a slice of array or tuple from start to end. The range is half
    open, [start, end). Indexes can also be negative, indicating indexing
    from the end of the end of the array. By default, start is 0 and end is
    the length of the array. Note that index -1 is synonymous with index
    (length arrtup) to allow a full negative slice range. Returns a new
    array.


1 exampleSign in to add an example
Loading...
(array/slice @[1 2 3] 0 0)  # => @[]
(array/slice @[1 2 3] 0 1)  # => @[1]
(array/slice @[1 2 3] 0 2)  # => @[1 2]
(array/slice @[1 2 3] 0 3)  # => @[1 2 3]
(array/slice @[1 2 3] 0 4)  # error: index out of range

(array/slice @[1 2 3] 1 1)  # => @[]
(array/slice @[1 2 3] 1 2)  # => @[2]

(array/slice @[1 2 3] 0 -1)  # => @[1 2 3]
(array/slice @[1 2 3] 0 -2)  # => @[1 2]
(array/slice @[1 2 3] 0 -3)  # => @[1]
(array/slice @[1 2 3] 0 -4)  # => @[]
(array/slice @[1 2 3] 0 -5)  # error: index out of range
cellularmitosis