<commit_before>angular.module('myApp.top100visual', [] )
  .controller('top100visualController', function($scope, $http, $firebase, $q, myName){
    $scope.dood = "dooood";

    var hackerNewsReference = new Firebase("https://hacker-news.firebaseio.com/v0/topstories");
    // create an AngularFire reference to the data
    var top100stories = $firebase(hackerNewsReference);
    // download the data into a local object
    top100stories = top100stories.$asArray();

    $scope.storyTitles = [];
    $scope.wordCount = {};
    $scope.loading = true;

    var grabTitles = function() {

      for (var index = 0; index < 99; index++) {
        var string = "" + index;
        $http.get('https://hacker-news.firebaseio.com/v0/item/' + top100stories.$getRecord(string).$value + ".json")
          .success(function(data) {
            $scope.storyTitles.push(data.title);
          });
      }
      $http.get('https://hacker-news.firebaseio.com/v0/item/' + top100stories.$getRecord("99").$value + ".json")
          .success(function(data) {
            $scope.storyTitles.push(data.title);
            $scope.wordCount = countWords($scope.storyTitles);
            myName.link($scope);
            $scope.loading = false;
          });
    };

    var countWords = function(titles) {
      var totalWordCount = {};
      for (var title = 0; title < titles.length; title++) {
        if (titles[title]) {
          var words = titles[title].split(" ");
          for (var word = 0; word < words.length; word++) {
            if (totalWordCount[words[word]] === undefined) {
              totalWordCount[words[word]] = 1;
            } else {
              totalWordCount[words[word]]++;
            }
          }
        }
      }

      var wordsForD3 = [];

      for (var wordCount in totalWordCount) {
        var tempObject = {};

        tempObject.count = totalWordCount[wordCount];
        tempObject.word = wordCount;
        
        wordsForD3.push(tempObject);
      }
      return wordsForD3;
    };

    top100stories.$loaded()
      .then(function() {
        grabTitles();
      });

  });<commit_msg>(refactor) Moved part of count words out into its own function for modularity.<commit_after>angular.module('myApp.top100visual', [] )
  .controller('top100visualController', function($scope, $http, $firebase, $q, myName){
    $scope.dood = "dooood";

    var hackerNewsReference = new Firebase("https://hacker-news.firebaseio.com/v0/topstories");
    // create an AngularFire reference to the data
    var top100stories = $firebase(hackerNewsReference);
    // download the data into a local object
    top100stories = top100stories.$asArray();

    $scope.storyTitles = [];
    $scope.wordCount = {};
    $scope.loading = true;

    var grabTitles = function() {

      for (var index = 0; index < 99; index++) {
        var string = "" + index;
        $http.get('https://hacker-news.firebaseio.com/v0/item/' + top100stories.$getRecord(string).$value + ".json")
          .success(function(data) {
            $scope.storyTitles.push(data.title);
          });
      }
      $http.get('https://hacker-news.firebaseio.com/v0/item/' + top100stories.$getRecord("99").$value + ".json")
          .success(function(data) {
            $scope.storyTitles.push(data.title);
            $scope.wordCount = countWords($scope.storyTitles);
            myName.link($scope);
            $scope.loading = false;
          });
    };

    var giveD3Words = function(wordsObject) {
      var wordsForD3 = [];

      for (var wordCount in wordsObject) {
        var tempObject = {};

        tempObject.count = wordsObject[wordCount];
        tempObject.word = wordCount;
        
        wordsForD3.push(tempObject);
      }
      return wordsForD3;
    };

    var countWords = function(titles) {
      var totalWordCount = {};
      for (var title = 0; title < titles.length; title++) {
        if (titles[title]) {
          var words = titles[title].split(" ");
          for (var word = 0; word < words.length; word++) {
            if (totalWordCount[words[word]] === undefined) {
              totalWordCount[words[word]] = 1;
            } else {
              totalWordCount[words[word]]++;
            }
          }
        }
      }
      
      return giveD3Words(totalWordCount);
    };

    

    top100stories.$loaded()
      .then(function() {
        grabTitles();
      });

  });
{'fraction_non_alphanumeric': 0.14671814671814673, 'fraction_numerical': 0.01771519418578242, 'mean_word_length': 2.216946676406136, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7570451', 'n_tokens_mistral': 1410, 'n_tokens_neox': 1327, 'n_words': 245}