text: 
  /*********************** VARIABLES ***************************************/
  
  var numberOfCand = 15;
  var numberOfSeats = 9;
  var electOff = [];
  var defeatOff = [];
  var ballot = [];
  var countArray = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
  var maxBallot = [];
  var minBallot = [0];
  var distCand = [];
  var defeatCount = 0;
  var numberOfBallots = 100000;
  
  /******** REFERENCE ARRAY ****************************************/
  // arr = [2,11,1,3] arr.sort() = [1,11,2,3] // we cannot sort the ballots any other way...
  function ballotArray() {
  		temp_arr = [];
    	for (i=0; i<countArray.length; i++){
  			temp_arr.push(i);
  		}
  		return temp_arr.sort()
  }
  
  /*********************** MAKES RANDOM BALLOT***********************************/
  // Eventually we will will generate ballots using jquery in the web page
  
  function shuffle(array) {
    var currentIndex = array.length, temporaryValue, randomIndex ;
  
    // While there remain elements to shuffle...
    while (0 !== currentIndex) {
  
      // Pick a remaining element...
      randomIndex = Math.floor(Math.random() * currentIndex);
      currentIndex -= 1;
  
      // And swap it with the current element.
      temporaryValue = array[currentIndex];
      array[currentIndex] = array[randomIndex];
      array[randomIndex] = temporaryValue;
    }
  
    return array;
  }
  
  /*********************** CREATES (X) AMOUNT OF BALLOTS ***************************************/
  // Used in conjunction with shuffle() to randomize the rank of the candidates
  // this simulates "numberOfBallots" people voting
  
  function vote(nB,nC) { //nB = numberOfBallots, nC = numberOfCand
    var arr = [];
  		for (var i=0; i<nB; i++){
  			for(var j=0;j<nC;j++){
        	arr[j] = j;
      	} 
  		ballot[i] = shuffle(arr);
  		}
    return ballot;
  }
  
  /*********************** REPLICATES ARRAY ***************************************/
  
  function createArr() { //cA = countArray
  	arr =[]
  	for (i=0; i<countArray.length; i++){
  		arr.push(cA[i]);
  	}
  	return arr;
  }
  /*********************** QUOTA ***************************************/
  
  function quota(nB,nS) {
  	q = (nB/(nS+1))+1;
  	return q;
  }
  
  
  
  /*********************** COMPARES NUMBERS ***************************************/
  
  function compareNumbers(a,b) {
      return a - b;
  }
  
  /*********************** REARANGES ***************************************/
  
  function rearrange(arr,cA) {
  	
  	temp_arrA = [];
  	temp_arrB = [] 
  	
  	for (i=0; i<cA.length; i++){
  		temp_arrA.push(i);
  		temp_arrB.push(arr[i])
  		
  		}
  		
  		temp_arrA.sort();
  		
  	for (i=0; i<cA.length; i++){	
  		
  		a = temp_arrA[i];
  		b = temp_arrB[a];
  		c = temp_arrB[i];
  		d = temp_arrA.indexOf(i);
  		arr[i]=b;
  		arr[d]=c;
  		}
  }
  
  /*********************** MAX RANGE  ***************************************/
  /* ballots have been arranged by first place votes [0,1,10,11,12,13,14,2,3,4,5,6,7,8,9],
  this function creates an array "maxBallot", of the uppermost range of indexes for this ^ particular array "ballotArray" */ 
  function ballotMax(cA) {
  	var max = 0;
  		for (var i=0;i<cA.length; i++){
  			temp_arr = ballotArray(); // makes an array replicating the order of the ballots
  			a = temp_arr[i] // stores the index of ballot in a variable
  			max = max + cA[a]; // uses "a" as index of array to add to counter variable "max"
  			maxBallot.push(max-1); // pushes the uppermost value of a ballot place into array
  		}	
  }
  
  /*********************** MIN RANGE ***************************************/
  // Places the first ballot index (ballot[i]) for a respective candidate into a respective array (minBallot)
  
  function ballotMin(cA) {
  	var min = 0;
  		for (var i=0;i<cA.length-1; i++){ //always starts at index zero
  			temp_arr = ballotArray();
  			a = temp_arr[i]
  			min = min + cA[a];
  			minBallot.push(min);// same as "ballotMax" expect pushes the lowermost value of a ballot place into array
  		}	
  }
  
  /*********************** PICKS A BALLOT TO DISTRIBUTE ***************************************/
  // Used in conjunction with maxBallot and minBallot
  // In order for the ballot distribution process to be valid you must pick the ballot at random
  
  function randomBallot(min,max) {
  	  return Math.floor(Math.random()*(max-min+1)+min); 
  }
  
  /*********************** COUNTS 1ST PLACE VOTES ***************************************/
  // Places the first place vote of each ballot into their respective index in "countArray", for each candidate.
  
  function countVotes(b,nC,cA) {
    var b = vote();
  	loop1:  
  		for(var i=0; i<b.length; i++){
  			loop2:
  				for(var z=0;z<nC;z++){ 	
  					if(b[i][0]==z){ 
  							cA[z] = cA[z] + 1
  							break loop2;
  					}
  				}
  			}
  		//console.log(countArray);
  }
  
  /*********************** ELECTS ***************************************/
  // If a candidate has first place votes >= the quota they are elected. (Quota being 10,001)
  
  function elect(cA,eO) { //eO = electOff
  
  	for (var k=0; k<cA.length; k++){
  		if (cA[k]>=10001 && eO.indexOf(k)==-1){
  			eO.push(k);
  			}
  		}
  }
  /*********************** FIRST DISTRIBUTION  ***************************************/
  //Any candidate who has first place votes > the quota are determined to be surplus
  // The surplus is then distributed to the next choice on a random ballot 
  
  function initDistribute() {
  	
  	for (var x=0; x<countArray.length; x++) {
  	
  		if (countArray[x]>=10001 && distCand.indexOf(x)==-1) {
  		
  			surplus = countArray[x]%10001;
  			
  			loop1:
  			for (var s=0; s<surplus; s++) {
  				
  				temp_arr = ballotArray();
  				a = temp_arr.indexOf(x)
  				b = randomBallot(minBallot[a],maxBallot[a]);
  					
  				loop2:
  				for (var j=1; j<numberOfCand; j++) {
  					
  				loop3:
  				for(var z=0;z<numberOfCand;z++) {
  			
  					if(ballot[b][j]==z){ 
  					
  							if (countArray[z]==10001 && electOff.indexOf(z)==-1){
  								electOff.push(z);
  								break loop3;
  							}
  				
  							else if(electOff.indexOf(z)==-1 && defeatOff.indexOf(z)==-1) {
  					
  							countArray[z] = countArray[z] + 1
  							break loop2;
  							} 
  							
  							else { 
  								break loop3;
  							}
  						}	
  					}	
  				}
  			}
  		}
  	}
  }
  /*********************** DECLARING A CANDIDATE DEFEATED  ***************************************/
  // after surplus ballots have been distributed candidate with least amount of votes is declared defeated
  // their votes are then distributed (example 100 votes = quota, (180 votes /quota) = surplus "distributable ballots")
  
  function defeatedCand() { 
  	
  	gradientArr = createArr();
  	gradientArr.sort(compareNumbers);
  	minVal = gradientArr[defeatCount];//min value of array
  	minIndex = countArray.indexOf(minVal);//index of min value in countArray
  	defeatOff.push(minIndex);
  	
  	loop1:
  	for (var s=0; s<minVal; s++) {
  		
  		temp_arr = ballotArray();
  		a = temp_arr.indexOf(minIndex)
  		b = randomBallot(minBallot[a],maxBallot[a]);
  
  		loop2:
  		for (var j=1; j<numberOfCand; j++) {
  
  			loop3:
  			for(var z=0;z<numberOfCand;z++) {
  				
  				if(ballot[b][j]==z){ 
  					
  					 if(electOff.indexOf(z)==-1 && defeatOff.indexOf(z)==-1) {
  				
  						countArray[z] = countArray[z] + 1
  						break loop2;
  					
  					}
  	
  					else { 
  						break loop3;
  					}
  				}
  			}	
  		}
  	}
  	defeatCount++;
  }
  /*********************** THE WHOLE SHEBANG ***************************************/
  
  function complete() {
  
  
  
  	console.log(electOff);
  	countVotes();
  	ballotMax();
  	ballotMin();
  	ballot.sort();
  
  	while (electOff.length<9){
  		elect();
  		initDistribute()
  		defeatedCand();
  		}
  	}
  
  //complete();
  console.log(electOff);
  
  // 	countVotes();
  // 	ballotMax();
  // 	ballotMin();
  // 	elect();
  // 	initDistribute();
  // 	defeatedCand();