├── package.json └── index.js /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "planets-project", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "csv-parse": "^5.5.6" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const { parse } = require('csv-parse'); 2 | const fs = require('fs'); 3 | 4 | const habitablePlanets = []; 5 | 6 | function isHabitablePlanet(planet) { 7 | return planet['koi_disposition'] === 'CONFIRMED' 8 | && planet['koi_insol'] > 0.36 && planet['koi_insol'] < 1.11 9 | && planet['koi_prad'] < 1.6; 10 | } 11 | 12 | fs.createReadStream('kepler_data.csv') 13 | .pipe(parse({ 14 | comment: '#', 15 | columns: true, 16 | })) 17 | .on('data', (data) => { 18 | if (isHabitablePlanet(data)) { 19 | habitablePlanets.push(data); 20 | } 21 | }) 22 | .on('error', (err) => { 23 | console.log(err); 24 | }) 25 | .on('end', () => { 26 | console.log(habitablePlanets.map((planet) => { 27 | return planet['kepler_name']; 28 | })); 29 | console.log(`${habitablePlanets.length} habitable planets found!`); 30 | }); 31 | 32 | --------------------------------------------------------------------------------