'use strict';

exports.list = function list(phrase1, phrase2, options) {

  options = options || {};

  options.ignoreCase = options.ignoreCase || false;
  options.minWordLength = options.minWordLength || 0;
  options.ignoreCommonWords = options.ignoreCommonWords || false;

  if (options.ignoreCase) {
    phrase1 = phrase1.toLowerCase();
    phrase2 = phrase2.toLowerCase();
  }

  var compare1 = tokenize(sanitize(phrase1)),
    compare2 = tokenize(sanitize(phrase2)),
    answer = [];

  if (options.ignoreCommonWords) {
    compare1 = removeCommonWords(compare1);
    compare2 = removeCommonWords(compare2);
  }

  compare1.forEach(function(element) {
    if (compare2.indexOf(element) > -1) {
      answer.push(element);
    }
  });

  answer = answer.filter(onlyUnique);

  if (options.minWordLength) {
    answer = answer.filter(getWordsWithMinLen.bind(this, options.minWordLength));
  }

  return answer;

}

function sanitize(word) {
  var punctuationRegex = /[\.,\/\?#!$%\^&\*;:{}=_`~()]/g;
  return word.replace(punctuationRegex, '');
}

function tokenize(word) {
  return word.split(' ');
}

function onlyUnique(value, index, self) {
  return self.indexOf(value) === index;
}

function removeCommonWords(words) {
  var commonWords = [
    'a', 'an', 'the', 'this', 'that', 'there', 'it',
    'in', 'on', 'for', 'not', 'your', 'you', 'at',
    'to', 'is', 'us', 'out', 'by', 'I' ];
  // a, an, the, this, that, there, it
  // on, for, not, your, you, at, to, is, us, out, by, I

  return words.filter(function(element) {
    return commonWords.indexOf(element) < 0;
  });
}

function getWordsWithMinLen(minLen, word) {
  return word.length >= minLen;
}

if (process.env.NODE_ENV === 'test') {
  exports.sanitize = sanitize;
  exports.tokenize = tokenize;
  exports.getWordsWithMinLen = getWordsWithMinLen;
}

@@ -933,24 +933,135 @@
 ize(word) %7B%0A
+  // matches common punctuations:%0A  // . , / ? # ! $ %25 %5E & * ; : %7B %7D = _ %60 ~ ( )%0A  // does not match hyphen: -%0A
   var punctu

add comments to regex - #5