Guest User

Untitled

a guest
Dec 16th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. const csv = require('csvtojson')
  2. const fs = require('fs')
  3.  
  4. csv()
  5. .fromFile('./StudentsPerformance.csv')
  6. .then(array => {
  7. return array.map((value, i) => {
  8. const val =
  9. parseInt(
  10. (Number(value['math score']) +
  11. Number(value['reading score']) +
  12. Number(value['writing score'])) /
  13. 3
  14. ) >= 60
  15. ? true
  16. : false
  17.  
  18. return { ...value, 'is approved': val }
  19. })
  20. })
  21. .then(data =>
  22. fs.writeFile(
  23. './StudentsPerformance.json',
  24. JSON.stringify(data),
  25. (err, data) => {
  26. if (err) console.log(err)
  27. else console.log('done!')
  28. }
  29. )
  30. )
Add Comment
Please, Sign In to add comment