Skip to content

Commit 6bc2d0d

Browse files
committed
correct get for negative indices for take/skip
1 parent 430a8a6 commit 6bc2d0d

File tree

3 files changed

+31
-21
lines changed

3 files changed

+31
-21
lines changed

dist/Immutable.js

+14-12
Original file line numberDiff line numberDiff line change
@@ -679,12 +679,13 @@ var $IndexedSequence = IndexedSequence;
679679
return this.get(this.length ? this.length - 1 : 0);
680680
},
681681
skip: function(amount) {
682-
var $__0 = this;
683-
var skipSeq = skipFactory(this, amount, false);
684-
if (skipSeq !== this) {
685-
skipSeq.get = (function(index, notSetValue) {
686-
return $__0.get(index + amount, notSetValue);
687-
});
682+
var seq = this;
683+
var skipSeq = skipFactory(seq, amount, false);
684+
if (skipSeq !== seq) {
685+
skipSeq.get = function(index, notSetValue) {
686+
index = wrapIndex(this, index);
687+
return index < 0 ? notSetValue : seq.get(index + amount, notSetValue);
688+
};
688689
}
689690
return skipSeq;
690691
},
@@ -699,12 +700,13 @@ var $IndexedSequence = IndexedSequence;
699700
}))).fromEntrySeq().valueSeq();
700701
},
701702
take: function(amount) {
702-
var $__0 = this;
703-
var takeSeq = takeFactory(this, amount);
704-
if (takeSeq !== this) {
705-
takeSeq.get = (function(index, notSetValue) {
706-
return index < amount ? $__0.get(index, notSetValue) : notSetValue;
707-
});
703+
var seq = this;
704+
var takeSeq = takeFactory(seq, amount);
705+
if (takeSeq !== seq) {
706+
takeSeq.get = function(index, notSetValue) {
707+
index = wrapIndex(this, index);
708+
return index < amount ? seq.get(index, notSetValue) : notSetValue;
709+
};
708710
}
709711
return takeSeq;
710712
},

0 commit comments

Comments
 (0)