var substringMatcher = function(strs) {
  return function findMatches(q, cb) {
    var matches, substringRegex;
    // an array that will be populated with substring matches
    matches = [];
    // regex used to determine if a string contains the substring `q`
    substrRegex = new RegExp(q, 'i');
    // iterate through the pool of strings and for any string that
    // contains the substring `q`, add it to the `matches` array
    $.each(strs, function(i, str) {
      if (substrRegex.test(str)) {
        matches.push(str);
      }
    });
    cb(matches);
  };
};
var mask = q.toLowerCase();
var matches = 
  strs.filter(function(str) { 
    return str.toLowerCase().includes(mask); 
  }).sort(function(str1, str2) { 
    return str1.toLowerCase().indexOf(mask) - str2.toLowerCase().indexOf(mask); 
  });var re = new RegExp(q, 'i');
var matches = 
  strs.filter(function(str) { 
    return str.match(re); 
  }).sort(function(str1, str2) { 
    return str1.search(re) - str2.search(re); 
  });var substringMatcher = function (strs) {
    return function findMatches(q, cb) {
        var matches, substrRegex;
        substrRegex = new RegExp(q, 'i');
        matches = strs.map(function (str) {
            return {pos: str.search(substrRegex), str: str};
        }).filter(function (a) {
            return a.pos > 0;
        }).sort(function (a, b) {
            return a.pos > b.pos;
        }).map(function (a) {
            return a.str;
        });
        cb(matches);
    };
};