Skip to content

Instantly share code, notes, and snippets.

@agsdot
Created May 23, 2016 19:05
Show Gist options
  • Save agsdot/bdd770791d5cef3fd87ebad89e871a53 to your computer and use it in GitHub Desktop.
Save agsdot/bdd770791d5cef3fd87ebad89e871a53 to your computer and use it in GitHub Desktop.
var request = require('request');
var options = {
method: 'GET',
json: {},
uri: 'https://api.clever.com/v1.1/districts/4fd43cc56d11340000000005/sections',
headers: {
Authorization: 'Bearer DEMO_TOKEN'
}
};
request(options, function(err, response, body) {
var numberOfSections, studentTotal, avgStudentsPerSection;
numberOfSections = body.data.length;
studentTotal = body.data.reduce(function(prevValue, currValue) {
var studentCountSection = currValue.data.students.length;
var studentCountTotal = studentCountSection + prevValue;
return studentCountTotal;
}, 0)
avgStudentsPerSection = studentTotal / numberOfSections;
console.log("number of sections");
console.log(numberOfSections);
console.log("total number of students in all the sections");
console.log(studentTotal);
console.log("average number of students per section");
console.log(avgStudentsPerSection)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment