Skip to content

Instantly share code, notes, and snippets.

@121onto
Last active April 13, 2016 03:54
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 121onto/f21560b8f25d80d0d2c4c54be99e7c18 to your computer and use it in GitHub Desktop.
Save 121onto/f21560b8f25d80d0d2c4c54be99e7c18 to your computer and use it in GitHub Desktop.
Display ratings on a yelp page as an array
// get array of ratings
var ratings = $("i.star-img")
.map(function(){return $(this).attr( "title" )})
.map(function(){return this.split(/[ ,]+/)})
.map(function(){return Number(this)})
.filter(function(){return this >= 0})
.toArray()
// print summary stats
console.log("LEN: ", ratings.length)
console.log("SUM: ", ratings.reduce(function(pv, cv) { return pv + cv; }))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment