Skip to content

Instantly share code, notes, and snippets.

@kavinyao
Created June 30, 2012 01:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kavinyao/3021705 to your computer and use it in GitHub Desktop.
Save kavinyao/3021705 to your computer and use it in GitHub Desktop.
Calculate the average status length in current Fanfou page
/**
* 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