"use strict";

var assert = require('assert');

var smush2 = function(a,b) {
  if (b.indexOf(a) === 0) {
    return b;
  } 

  return a[0] + smush2(a.substr(1), b);
};

var smush = function() {
  if (arguments.length === 2) {
    var resultA = smush2(arguments[0], arguments[1]);
    var resultB = smush2(arguments[1], arguments[0]);

    return resultA.length > resultB.length ? resultB : resultA;
  }
};

describe('word smush', function() {
  describe('smush two works', function() {
    it('should concatenate words with no overlaps', function() {
      assert.equal("catdog", smush2("cat", "dog"));
    });

    it('should skip adjacent characters', function() {
      assert.equal('find', smush2('fin', 'ind'));
    });
  });

  describe('minimal solution', function() {
    it('should find the minimal solution for two words', function() {
      assert.equal('boing', smush('ing', 'boi'));
    });
  });
});
@@ -162,16 +162,85 @@
 b);%0A%7D;%0A%0A
+var best = function(x,y) %7B%0A  return x.length %3E y.length ? y : x;%0A%7D;%0A%0A
 var smus
@@ -412,59 +412,30 @@
 urn 
-resultA.length %3E resultB.length ? resultB : resultA
+best(resultA, resultB)
 ;%0A  

refactor our a method