-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
listing-6.2.js
38 lines (32 loc) · 1.04 KB
/
listing-6.2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//
// Example that imports a CSV file, fixes date/time values in each row and exporting a new CSV file.
// Date/times are fixed by encoding in UTC so that the correct timezone is preserved.
//
"use strict";
const moment = require('moment');
const importCsvFile = require('./toolkit/importCsvFile.js');
const exportCsvFile = require('./toolkit/exportCsvFile.js');
const inputFileName = "./data/surveys.csv";
const outputFileName = "./output/surveys-with-fixed-dates.csv";
function transformRow (inputRow) {
const outputRow = Object.assign({}, inputRow);
//
// TODO: Your code here to fix the row of data.
//
return outputRow;
}
function transformData (inputData) {
return inputData.map(transformRow);
}
importCsvFile(inputFileName)
.then(inputData => {
const outputData = transformData(inputData);
return exportCsvFile(outputFileName, outputData);
})
.then(() => {
console.log("Done!");
})
.catch(err => {
console.error("Error!");
console.error(err && err.stack || err);
});