Created
June 7, 2016 19:01
-
-
Save louisbuchbinder/ccac2749991a785d217c244d075f2701 to your computer and use it in GitHub Desktop.
Clever average students per section
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
// rl-stdin is a node module I wrote to the stdin data and resolve the result in a promise | |
// `sudo npm install -g rl-stdin` | |
require('rl-stdin') // get the stdin data from the curl | |
.then(JSON.parse) // convert JSON to javascript object | |
.then((data) => data.data) // data is stored at the data key | |
.then((data) => data.map((section) => section.data.students.length)) // map the section to the number of students enrolled | |
.then((data) => data.reduce((hold, current) => hold + current)/data.length) // sum the total number of students enrolled divided by the total number of sections to get the average | |
.then((solution) => console.log('Average students per section is: ' + solution)); // log the output |
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
#!/bin/bash | |
# Fetch the sections data with curl and the DEMO_TOKEN and pipe the reslut to the index.js | |
curl -H 'Authorization: Bearer DEMO_TOKEN' -X GET https://api.clever.com/v1.1/sections | node index.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment