var Transform = require('stream').Transform

  , BASE = 65536
  , NMAX = 65221

  , rolling = function(length, interval) {
      var stream = new Transform({objectMode: true})
        , data = []
        , a = 1
        , b = 0
        , collecting = true
        , step = 0

      if (interval === undefined)
        interval = 1

      stream._transform = function(chunk, encoding, callback) {
        var i
          , tmp1, tmp2

        if (encoding !== 'buffer')
          chunk = new Buffer(chunk, encoding)

        for(i = 0; i < chunk.length; ++i) {
          data.push(chunk[i])
        }

        if (collecting && data.length >= length) {
          for(i = 0; i < length; ++i) {
            a = (a + data[i]) % NMAX
            b = (b + (length - i) * data[i] + 1) % NMAX
          }
          this.push(b * BASE + a)

          collecting = false
        }

        while (data.length > length) {
          step++

          tmp2 = data[length]
          tmp1 = data.shift()
          a = (a - tmp1 + tmp2 + BASE) % BASE
          b = (b - length * tmp1 + a - 1)
          if (step % interval === 0) {
            this.push(b * BASE + a)
          }
        }

        callback(null)
      }

      return stream
    }

module.exports = rolling

@@ -877,15 +877,23 @@
     
-while (
+for(i = 0; i %3C 
 data
@@ -904,16 +904,21 @@
 gth 
-%3E
+-
  length
+; ++i
 ) %7B%0A
@@ -952,17 +952,17 @@
  tmp
-2
+1
  = data%5B
 leng
@@ -957,22 +957,17 @@
  = data%5B
-length
+i
 %5D%0A      
@@ -977,24 +977,29 @@
  tmp
-1
+2
  = data
-.shift()
+%5Bi + length%5D%0A
 %0A   
@@ -1083,16 +1083,17 @@
  a - 1)%0A
+%0A
         
@@ -1174,32 +1174,68 @@
    %7D%0A        %7D%0A%0A
+        data = data.slice(-length)%0A%0A
         callback

use data.slice instead of data.shift