Guest User

Untitled

a guest
Feb 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. // Collecting all unique affected app version for a given data set
  2. var jsonStats = [
  3. {app_versions: ['1.2','1.2.3']},
  4. {app_versions: null},
  5. {app_versions: ['1.2','1.3']}
  6. ];
  7. var app_versions = _.uniq(_.flatten(_.compact(_.map(jsonStats, function(day){return day.app_versions }))));
  8. // ["1.2", "1.2.3", "1.3"]
  9.  
  10. // Bye bye stupid for loops!
  11. _.each(app_versions, function(av){ alert(av); })
  12.  
  13. // Sum up everything
  14. _.reduce(data.total_errors_spline, function(a,b) { return a+b });
  15.  
  16. // Select only the days that the app versions 1.2 is affected
  17. var dayStats =_.select(jsonStats, function(day){ return _.any(day.app_versions,function(av){ return av==='1.2' }) })
  18.  
  19. // And you can even display them!
  20. _.template("These versions are affected on day 1: <%= ds[0].app_versions.join(', ') %>")({ds: dayStats })
  21. // "These versions are affected on day 1: 1.2, 1.2.3"
Add Comment
Please, Sign In to add comment