Fix to included last element in reversed
This commit is contained in:
parent
c591db16c8
commit
8b796763a3
1 changed files with 2 additions and 2 deletions
|
|
@ -36,10 +36,10 @@ proc reverse*[T](a: var openArray[T]) =
|
||||||
|
|
||||||
proc reversed*[T](a: openArray[T], first, last: int): seq[T] =
|
proc reversed*[T](a: openArray[T], first, last: int): 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)
|
result = newSeq[T](last - first + 1)
|
||||||
var x = first
|
var x = first
|
||||||
var y = last
|
var y = last
|
||||||
while x < last:
|
while x <= last:
|
||||||
result[x] = a[y]
|
result[x] = a[y]
|
||||||
dec(y)
|
dec(y)
|
||||||
inc(x)
|
inc(x)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue