-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlisting-6.5.js
35 lines (29 loc) · 988 Bytes
/
listing-6.5.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
//
// This example imports a CSV file, filters out any row that is not associated with Australia and
// exports a new CSV file.
//
"use strict";
const importCsvFile = require('./toolkit/importCsvFile.js');
const exportCsvFile = require('./toolkit/exportCsvFile.js');
const inputFileName = "./data/surveys.csv";
const outputFileName = "./output/surveys-but-only-Australia.csv";
function filterRow (inputRow) {
//TODO: Your predicate here. Return true to preserve the row of data or false to filter it out.
const preserveRow = true;
return preserveRow;
}
function transformData (inputData) {
return inputData.filter(filterRow);
};
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);
});