Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 9th, 2012  |  syntax: None  |  size: 0.55 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. pubic function RLEEncoder(data)
  2. {
  3.         var str = "";
  4.         for(var i = 0; i < data.length; i+=2)
  5.         {
  6.                 var rleValue = data[i];
  7.                 var rleSequenceLength = data[i+1];
  8.  
  9.                 if(rleValue < 3) // Sequences are captured for blanks, walls or grains
  10.                         var asciiCode = 36 + (rleValue * 30) + (rleSequenceLength - 1);
  11.                 else // remaining cell types (3 and 4) are treated as one-offs
  12.                         var asciiCode = 33 + (rleValue - 3);
  13.  
  14.                 // Special case for eliminated semi-colons
  15.                 if(asciiCode == 59)
  16.                         asciiCode = 35;
  17.  
  18.                 str += String.fromCharCode(asciiCode);
  19.         }
  20.         return str;
  21. }