Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Enumerable.prototype.where = function(predicate) {
- var e = this.getEnumerator();
- return new Enumerable(function() {
- while(true) {
- if(!e.next())
- return { finished: true };
- if(predicate(e.current()))
- return { finished: false, val: e.current() };
- }
- });
- };
- Enumerable.prototype.select = function(selector) {
- var e = this.getEnumerator();
- return new Enumerable(function() {
- if(!e.next())
- return { finished: true };
- return { finished: false, val: selector(e.current()) };
- });
- };
- Enumerable.prototype.each = function(fn) {
- var e = this.getEnumerator();
- while(e.next())
- fn(e.current());
- };
- Enumerable.prototype.reverse = function() {
- var stack = [];
- this.each(function(x) { stack.unshift(x); });
- return new Enumerable(stack);
- };
- Enumerable.prototype.at = function(index) {
- var e = this.getEnumerator();
- var i = -1;
- while(e.next())
- {
- i++;
- if(i == index)
- return e.current();
- }
- return null;
- };
- Enumerable.prototype.len = function() {
- var e = this.getEnumerator();
- var len = 0;
- while(e.next())
- len++;
- return len;
- };
- Enumerable.prototype.array = function() {
- var a = [];
- var e = this.getEnumerator();
- while(e.next())
- a.push(e.current());
- return a;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement