summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2014-07-15 19:10:19 +0200
committerAndreas Rumpf <rumpf_a@web.de>2014-07-15 19:10:19 +0200
commite0404609436eafdd7da79166fdb88a09d4f16451 (patch)
tree76172c2f7aa1696a08084a05373bc6a218fbeaeb
parent45bf087ce72e6ad703ebd97a91f844423738b956 (diff)
parentce3d1b302ebf30d93697be9c85112350bb9e4eb0 (diff)
downloadNim-e0404609436eafdd7da79166fdb88a09d4f16451.tar.gz
Merge pull request #1341 from def-/algorithm-reversed
Add reversed proc
-rw-r--r--lib/pure/algorithm.nim14
-rw-r--r--web/news.txt1
2 files changed, 15 insertions, 0 deletions
diff --git a/lib/pure/algorithm.nim b/lib/pure/algorithm.nim
index 86d329763..89c83a8a4 100644
--- a/lib/pure/algorithm.nim
+++ b/lib/pure/algorithm.nim
@@ -34,6 +34,20 @@ proc reverse*[T](a: var openArray[T]) =
   ## reverses the array `a`.
   reverse(a, 0, a.high)
 
+proc reversed*[T](a: openArray[T], first, last: int): seq[T] =
+  ## returns the reverse of the array `a[first..last]`.
+  result = newSeq[T](last - first + 1)
+  var x = first
+  var y = last
+  while x <= last:
+    result[x] = a[y]
+    dec(y)
+    inc(x)
+
+proc reversed*[T](a: openArray[T]): seq[T] =
+  ## returns the reverse of the array `a`.
+  reversed(a, 0, a.high)
+
 proc binarySearch*[T](a: openArray[T], key: T): int =
   ## binary search for `key` in `a`. Returns -1 if not found.
   var b = len(a)
diff --git a/web/news.txt b/web/news.txt
index aa91a83c4..a8d525443 100644
--- a/web/news.txt
+++ b/web/news.txt
@@ -24,6 +24,7 @@ News
   - Added module ``cpuinfo``.
   - Added module ``threadpool``.
   - ``sequtils.distnct`` has been renamed to ``sequtils.deduplicate``.
+  - Added ``algorithm.reversed``
 
 
 2014-04-21 Version 0.9.4 released