Skip to content

Commit

Permalink
fix bug in slice method
Browse files Browse the repository at this point in the history
  • Loading branch information
Denys-Bushulyak committed Feb 5, 2015
1 parent 36de0bc commit 59b7a8d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ function Chain(items) {

function _slice(start, length){
var out = [];
length = length || Number.POSITIVE_INFINITY;
for(var i in _items){
if(i >= start && i <= length){
out.push(_items[i]);
Expand Down
23 changes: 23 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,29 @@ describe("Testing Chain", function () {
})
});

describe("Testing slice function",function(){
var chain = new Chain(arr);

it("expecting chain will be 4 items length", function(){
expect(chain.count()).toBe(5);
});

it("expecting chain will be 4 items length", function(){

chain = chain.slice(1);

expect(chain.count()).toBe(4);
expect(chain.first()).toBe(1);
expect(chain.last()).toBe(null);
expect(chain.last()).toBeNull();

chain = chain.slice(1,2);

expect(chain.first()).toBe(3);
expect(chain.last()).toBe(-2);
});
});

describe("Begin sub chain", function(){
var chain = new Chain(arr);

Expand Down

0 comments on commit 59b7a8d

Please sign in to comment.