07.08 javascript saved
TJSingleton
Tags add more
 
Note
TJSingleton did not leave a note
  1. var arr = ['a', 'b', 'c', 'c', 'd','e', 'e',
  2. 'e', 'e', 'e', 'f', 'e', 'f', 'e',
  3. 'f', 'a', 'a', 'a', 'f', 'f', 'f'];
  4.  
  5. var output = '';
  6. var currentItem = '';
  7. var itemCounter = 0;
  8.  
  9. arr.forEach(function(item, index, ar) {
  10.     if(currentItem != item) {
  11.         if (itemCounter > 2) {
  12.             output = output + '</span>';
  13.         }
  14.         itemCounter = 0;
  15.     }
  16.     if(itemCounter == 2) {
  17.         output = output + '<span>';
  18.     }
  19.  
  20.     currentItem = item;
  21.     itemCounter = itemCounter +1;
  22.     output = output + item;
  23. })
Parsed in 0.009 seconds, using GeSHi 1.0.7.14

Modify this Paste