Fix algorithm.reversed to accept non-zero 'first' arg
This commit is contained in:
parent
cf63f90d0f
commit
f529e14b04
1 changed files with 5 additions and 5 deletions
|
|
@ -50,12 +50,12 @@ proc reverse*[T](a: var openArray[T]) =
|
||||||
|
|
||||||
proc reversed*[T](a: openArray[T], first, last: Natural): seq[T] =
|
proc reversed*[T](a: openArray[T], first, last: Natural): seq[T] =
|
||||||
## returns the reverse of the array `a[first..last]`.
|
## returns the reverse of the array `a[first..last]`.
|
||||||
result = newSeq[T](last - first + 1)
|
var i = last - first
|
||||||
var x = first.int
|
var x = first.int
|
||||||
var y = last.int
|
result = newSeq[T](i + 1)
|
||||||
while x <= last:
|
while i >= 0:
|
||||||
result[x] = a[y]
|
result[i] = a[x]
|
||||||
dec(y)
|
dec(i)
|
||||||
inc(x)
|
inc(x)
|
||||||
|
|
||||||
proc reversed*[T](a: openArray[T]): seq[T] =
|
proc reversed*[T](a: openArray[T]): seq[T] =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue