'use strict';

/**
 * @ngdoc filter
 * @name annotationAppApp.filter:filterStringsByStartsWith
 * @function
 * @description
 * # filterStringsByStartsWith
 * Filter in the annotationAppApp.
 */
angular.module('app')
	.filter('substringAttributes', function() {
		return function(input, attributes, query, activeSearch) {
      var insights = [];
      if (activeSearch !== 'search' || !query) {
        return input;
      }
      angular.forEach(input, function(insight, key) {

        attributes.forEach(function(attr){
          if(insight[attr] && insight[attr].toLowerCase().indexOf(query.toLowerCase()) > -1){
            this.push(insight);
            return;
          }
        },insights);

    	});

      return insights;
		};
	});
