angular.module("myApp").controller("RaceController", ['average', 'athletes', function(average, athletes) {
  var race = this;
  race.newAthlete = null;
  race.athletes = [];

  athletes.getAthletes().then(function (data) {
    race.athletes = data;
  });

  race.addAthlete = function(){
    race.newAthlete.average = average(race.newAthlete.time);
    race.athletes.push(race.newAthlete);
    race.newAthlete=null;
  };

  race.removeAthlete = function($index){
    race.athletes.splice($index,1);
  };

}]);
