const { List } = require('immutable');
const TYPES = require('./TYPES');

/**
 * Group changes to wrap identical nodes.
 * @param  {List<Change>} changes
 * @param  {Number} minToWrap
 * @return {List<Change|List<Change>} groups
 */
function groupChanges(changes, minToWrap) {
    if (!minToWrap) {
        return changes;
    }

    let results = [];
    let accu = [];

    changes.forEach((change, i) => {
        const isLast = (i == (changes.size - 1));
        const isIdentical = change.type == TYPES.IDENTICAL;

        if (isIdentical) {
            accu.push(change);
        }

        if (!isIdentical || isLast) {
            if (accu.length > minToWrap) {
                results.push(List(accu));
            } else {
                results = results.concat(accu);
            }
            accu = [];
        }

        if (!isIdentical) {
            results.push(change);
        }
    });

    return List(results);
}

module.exports = groupChanges;

@@ -177,16 +177,47 @@
 nToWrap%0A
+ * @param  %7BNumber%7D borderSize%0A
  * @retu
@@ -289,32 +289,48 @@
 anges, minToWrap
+, borderSize = 1
 ) %7B%0A    if (!min
@@ -730,31 +730,199 @@
     
-results.push(List(accu)
+const toWrap = accu.slice(0, -borderSize);%0A                const border = accu.slice(-borderSize);%0A%0A                results.push(List(toWrap));%0A                results = results.concat(border
 );%0A 

Fix #9: add border around toggable sections