function (needles, haystack) {
      var i,
          needleArr = needles.split(/\s+/g),
          needle,
          needleRegexpArr = [],
          regexp,
          retVal = true,
          hasUpperCase,
          regexpFlags;

      // Create filters on an 'and' basis (for 'or' use .join('|'))
      for (i = needleArr.length; i--;) {
        needle = needleArr[i];

        // If the item uses upper case, be case sensitive. Otherwise, don't.
        hasUpperCase = !!needle.match(/[A-Z]/),
        regexpFlags = hasUpperCase ? '' : 'i';

        // Generate the filter and push it onto the array
        needleRegexpArr.push( new RegExp(needle, regexpFlags) );
      }

      for (i = needleRegexpArr.length; i--;) {
        // If the unused option matches the regexp
        if (!haystack.match(needleRegexpArr[i])) {
          retVal = false;
          break;
        }
      }

      return retVal;
    }
function (needles, haystack) {
      var i,
          needleArr = needles.split(/\s+/g),
          needle,
          needleRegexpArr = [],
          regexp,
          retVal = true,
          hasUpperCase,
          regexpFlags;

      
      for (i = needleArr.length; i--;) {
        needle = needleArr[i];

        
        hasUpperCase = !!needle.match(/[A-Z]/),
        regexpFlags = hasUpperCase ? '' : 'i';

        
        needleRegexpArr.push( new RegExp(needle, regexpFlags) );
      }

      for (i = needleRegexpArr.length; i--;) {
        
        if (!haystack.match(needleRegexpArr[i])) {
          retVal = false;
          break;
        }
      }

      return retVal;
    }
function ( needles , haystack ) { var i , needleArr = needles . split ( / \s+ / g ) , needle , needleRegexpArr = [ ] , regexp , retVal = true , hasUpperCase , regexpFlags ; // Create filters on an 'and' basis (for 'or' use .join('|')) for ( i = needleArr . length ; i -- ; ) { needle = needleArr [ i ] ; // If the item uses upper case, be case sensitive. Otherwise, don't. hasUpperCase = ! ! needle . match ( / [A-Z] / ) , regexpFlags = hasUpperCase ? '' : 'i' ; // Generate the filter and push it onto the array needleRegexpArr . push ( new RegExp ( needle , regexpFlags ) ) ; } for ( i = needleRegexpArr . length ; i -- ; ) { // If the unused option matches the regexp if ( ! haystack . match ( needleRegexpArr [ i ] ) ) { retVal = false ; break ; } } return retVal ; }
fancyFilter, taken from https://github.com/Ensighten/Halo.extras/blob/master/src/public/js/Helper.js
fancyFilter taken from https : // github . com / Ensighten / Halo . extras / blob / master / src / public / js / Helper . js