The proc algorithm.reversed seems to be able to accept first and last (:Natural) args.
But IndexError is raised when first is not 0.
import algorithm
var array_0 = [0, 1, 2, 3, 4]
echo($array_0.reversed(0, 2)) # => @[2, 1, 0]
echo($array_0.reversed(1, 2)) # IndexError
Is this expected behavior ? I feel it should be as follows.
proc reversed*[T](a: openArray[T], first, last: Natural): seq[T] =
## returns the reverse of the array `a[first..last]`.
var i = last - first
var x = first.int
result = newSeq[T](i + 1)
while i >= 0:
result[i] = a[x]
dec(i)
inc(x)
var array_0 = [0, 1, 2, 3, 4]
echo($array_0.reversed(0, 2)) # => @[2, 1, 0]
echo($array_0.reversed(1, 2)) # => @[2, 1]