It appeared as a code kata, but it finished like a little library.
some tests
it("Given different lists with numbers when call zip method, return a list with zipped elements", function(){ var numbers = new List([1,3]); var result = numbers.zip(new List([2,4,6])); expect(result.isEqual(new List([1,2,3,4,6]))).to.be(true); }); it("Given list with numbers when call skip method then Ignores the specified number of items and returns a sequence starting at the item after the last skipped item (if any)", function(){ var numbers = new List([1,2,3,4,5,6,7,8]); var result = numbers.skip(3); expect(result.isEqual(new List([4,5,6,7,8]))).to.be(true); }); it("Given list with numbers when call apply condition with fluent api", function(){ var result = new List([1,2,4,3,5,3,7,9]) .where(function(x){ return x > 1}) .where(function(x){ return x < 5}); expect(result.isEqual(new List([2,4,3,3]))).to.be(true); }); describe(".orderBy()", function(){ it("Given list with numbers when call orderAscending method then returns an list ordered", function(){ var numbers = new List([{number:5, letra:'e'},{number:3, letra:'q'},{number:1, letra:'a'},{number:9, letra:'w'},{number:4, letra:'r'},{number:7, letra:'t'}]); var result = numbers.orderBy(function(x, y){ return (x.number - y.number); }); expect(result.isEqual(new List([{number:1, letra:'a'},{number:3, letra:'q'},{number:4, letra:'r'},{number:5, letra:'e'},{number:7, letra:'t'},{number:9, letra:'w'}]))) .to.be(true); }); });