summary refs log tree commit diff stats
diff options
context:
space:
mode:
authortakaomag <takaomag@users.noreply.github.com>2015-07-02 14:32:13 +0000
committertakaomag <takaomag@users.noreply.github.com>2015-07-02 14:32:13 +0000
commitf529e14b0443708292a506b3dcc01d0bdb093013 (patch)
tree1061adb02ef28b09289ee91fc2a74513baf42faa
parentcf63f90d0ff8586dfba218d2dd80bdb84bf69627 (diff)
downloadNim-f529e14b0443708292a506b3dcc01d0bdb093013.tar.gz
Fix algorithm.reversed to accept non-zero 'first' arg
-rw-r--r--lib/pure/algorithm.nim10
1 files changed, 5 insertions, 5 deletions
diff --git a/lib/pure/algorithm.nim b/lib/pure/algorithm.nim
index e087b5ac9..899420fca 100644
--- a/lib/pure/algorithm.nim
+++ b/lib/pure/algorithm.nim
@@ -50,12 +50,12 @@ proc reverse*[T](a: var openArray[T]) =
 
 proc reversed*[T](a: openArray[T], first, last: Natural): seq[T] =
   ## returns the reverse of the array `a[first..last]`.
-  result = newSeq[T](last - first + 1)
+  var i = last - first
   var x = first.int
-  var y = last.int
-  while x <= last:
-    result[x] = a[y]
-    dec(y)
+  result = newSeq[T](i + 1)
+  while i >= 0:
+    result[i] = a[x]
+    dec(i)
     inc(x)
 
 proc reversed*[T](a: openArray[T]): seq[T] =