Created
          August 22, 2012 17:10 
        
      - 
      
- 
        Save user24/3427621 to your computer and use it in GitHub Desktop. 
    facebook.js
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | var rawAnswers = [38,264,35]; | |
| // Truncate eg 12345 to 12 to account for data errors. | |
| var answers = []; | |
| rawAnswers.forEach(function(e, i, c) { | |
| answers.push(parseInt(e.toString().substring(0,2))); | |
| }); | |
| var correct=0,sum=0,b=[], mode='', maxi=0; | |
| answers.forEach(function(e) { | |
| // Find correct answers: | |
| if(e==40) { | |
| correct++; | |
| } | |
| // For average | |
| sum+=e; | |
| // Find mode | |
| if(b[e]) { | |
| b[e]++; | |
| } else { | |
| b[e]=1; | |
| } | |
| if(maxi<b[e]) { | |
| mode=e; | |
| maxi=b[e]; | |
| } | |
| }); | |
| answers = answers.sort(); | |
| console.log("Num: "+answers.length+", Correct:"+correct+" ("+Math.round(correct/answers.length*100)+"%), Min: "+answers[0]+", Max: "+answers[answers.length-1]+", Mode: "+mode+", Avg: "+Math.round(sum/answers.length)); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment