Created
June 30, 2012 01:34
-
-
Save kavinyao/3021705 to your computer and use it in GitHub Desktop.
Calculate the average status length in current Fanfou page
This file contains 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
/** | |
* What's the average status length in current Fanfou page? | |
* Author: @kavinyao | |
* MIT-licensed. | |
*/ | |
(function(document) { | |
function map(op, seq) { | |
var result = [] | |
for(var i = 0;i < seq.length;i++) | |
result.push(op(seq[i])) | |
return result | |
} | |
function reduce(op, seq, initial) { | |
var result = initial | |
for(var i = 0;i < seq.length;i++) | |
result = op(result, seq[i]) | |
return result | |
} | |
function average(seq) { | |
return reduce(function(x, y) { | |
return x+y | |
}, seq, 0.0) / seq.length | |
} | |
var spans = document.getElementsByClassName('content') | |
var lengths = map(function(s) { | |
return s.textContent.length | |
}, spans) | |
console.log(average(lengths)) | |
})(document) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment