1
var RLEIterator = function (encoding) {2
this.encoding = encoding;3
// Pointer to count index7
RLEIterator.prototype.next = function (n) {9
// Move to next count index when the current index is 010
if (this.encoding[this.index] === 0) this.index += 2;12
// Too many calls to next, return -113
if (this.index >= this.encoding.length) return -1;15
// n goes completely into count16
if (n <= this.encoding[this.index]) {17
this.encoding[this.index] -= n;19
// count goes completely into n20
} else if (n > this.encoding[this.index]) {21
n -= this.encoding[this.index];22
this.encoding[this.index] = 0;26
return this.encoding[this.index + 1];