(function () {
  'use strict';

  angular
    .module('fusionSeedApp.components.facetField', ['fusionSeedApp.services.config',
      'foundation.core'
    ])
    .directive('facetField', facetField);

  /* @ngInject */
  function facetField() {
    return {
      restrict: 'EA',
      templateUrl: 'assets/components/facetField/facetField.html',
      scope: true,
      controller: Controller,
      controllerAs: 'vm',
      bindToController: {
        facetName: '@facetName',
        facetLabel: '@facetLabel'
      }
    };

  }

  Controller.$inject = ['ConfigService', 'Orwell', 'FoundationApi'];

  /* @ngInject */
  function Controller(ConfigService, Orwell, FoundationApi) {
    var vm = this;
    vm.facetCounts = [];
    vm.toggleFacet = toggleFacet;
    var resultsObservable = Orwell.getObservable('queryResults');

    activate();

    function activate() {
      resultsObservable.addObserver(function (data) {
        var facetFields = data.facet_counts.facet_fields;
        if (facetFields.hasOwnProperty(vm.facetName)) {
          // Transform an array of values in format [‘aaaa’, 1234,’bbbb’,2345] into an array of objects.
          vm.facetCounts = _.transform(facetFields[vm.facetName], function (result,
            value, index) {
            if (index % 2 === 1) {
              result[result.length - 1] = {
                title: result[result.length - 1],
                amount: value,
                hash: FoundationApi.generateUuid()
              };
            } else {
              result.push(value);
            }
          });
        }
      });
    }

    function toggleFacet(){

    }
  }

})();

@@ -1,16 +1,29 @@
+/*global _*/%0A
 (function () %7B%0A 
@@ -1184,19 +1184,26 @@
 s = 
-_.transform
+arrayToObjectArray
 (fac
@@ -1228,39 +1228,525 @@
 ame%5D
-, function (result,
+);%0A        %7D%0A      %7D);%0A    %7D%0A%0A    /**%0A     * Turn a flat array into an object array.%0A     *%0A     * Transforms an array of values in format %5B'aaaa', 1234,'bbbb',2345%5D into%0A     * an array of objects.%0A     * %5B%7Btitle:'aaaa', amount:1234, hash: zf-hs-njkfhdsle%7D,%0A     *  %7Btitle:'bbbb', amount:2345, hash: zf-hs-jkewrkljn%7D%5D
 %0A     
+*%0A
      
- 
+* @param  %7Barray%7D arr The array to transform%0A     * @return %7Barray%7D     An array of objects%0A     */%0A    function arrayToObjectArray (arr)%7B%0A      return _.transform(arr, function (result,
  val
@@ -1754,28 +1754,24 @@
 e, index) %7B%0A
-    
         if (
@@ -1795,28 +1795,24 @@
 %7B%0A          
-   
- 
 result%5Bresul
@@ -1829,20 +1829,16 @@
  1%5D = %7B%0A
-    
         
@@ -1875,20 +1875,16 @@
 h - 1%5D,%0A
-    
         
@@ -1914,20 +1914,16 @@
         
-    
 hash: Fo
@@ -1959,20 +1959,16 @@
         
-    
 %7D;%0A     
@@ -1970,20 +1970,16 @@
         
- 
-   
 %7D else %7B
@@ -1979,20 +1979,16 @@
  else %7B%0A
-    
         
@@ -2013,36 +2013,8 @@
 e);%0A
-            %7D%0A          %7D);%0A
     

Add documentation for readability