diff options
author | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-05-22 15:09:57 +0200 |
---|---|---|
committer | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-05-22 15:09:57 +0200 |
commit | 2bb6bc03b5c7c2eb6465d2c05159028ede6c93b4 (patch) | |
tree | 4db98c30abef529df257ed37ba293ca028fbfdf2 /js/utility/Iterators.js | |
parent | 7d15bfa996e7661e450070715a96fe8cb2d75a8c (diff) |
add autopaging directive
Diffstat (limited to 'js/utility/Iterators.js')
-rw-r--r-- | js/utility/Iterators.js | 19 |
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 |