summaryrefslogtreecommitdiffstats
path: root/js/utility/Iterators.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/utility/Iterators.js')
-rw-r--r--js/utility/Iterators.js19
1 files changed, 19 insertions, 0 deletions
diff --git a/js/utility/Iterators.js b/js/utility/Iterators.js
index 3c5e34b18..1f96aab71 100644
--- a/js/utility/Iterators.js
+++ b/js/utility/Iterators.js
@@ -48,4 +48,23 @@ window.enumerate = function (list) {
})();
}
};
+};
+
+
+/**
+ * Iterates over a list in reverse
+ * like: for (let value of reverse(list))
+ */
+window.reverse = function (list) {
+ 'use strict';
+
+ return {
+ [Symbol.iterator]: function () {
+ return (function*() {
+ for (let counter = list.length; counter >= 0 ; counter -= 1) {
+ yield list[counter];
+ }
+ })();
+ }
+ };
}; \ No newline at end of file