Guest User

Untitled

a guest
Jan 21st, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. // UDACITY DAND - Data Visualisation - Giacomo Sarchioni
  2.  
  3. /*This JavaScript modules contains all the code for converting objects
  4. for the Data Analyst Nanodegree - Data Visualisation project.*/
  5.  
  6. // Convert countryData into an object format
  7. function convert_CountryData(countryData) {
  8.  
  9. return Object.keys(countryData)
  10. .map(function(key) {
  11. return {
  12. 'year': key,
  13. 'value': countryData[key]
  14. };
  15. });
  16.  
  17. };
  18.  
  19. function convert_NestedToObject(nested) {
  20.  
  21. nested.forEach(function(obj) {
  22.  
  23. newObj = {};
  24.  
  25. obj.values.forEach(function(d) {
  26.  
  27. newObj[d.year] = d.value;
  28.  
  29. });
  30.  
  31. // Replace array with object
  32. obj.values = newObj;
  33.  
  34. });
  35.  
  36. return nested;
  37.  
  38. }
  39.  
  40. // Convert Purpose Name ad-hoc
  41. function convert_PurposeName(purpose, datum) {
  42.  
  43. if(purpose == 'VFR') {
  44. return 'Visiting friends and relatives'
  45. } else {
  46. return datum.purpose;
  47. };
  48.  
  49. };
Add Comment
Please, Sign In to add comment