├── index.js ├── kepler_data.csv ├── package-lock.json └── package.json /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 | -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "planets-project", 3 | "version": "1.0.0", 4 | "lockfileVersion": 3, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "planets-project", 9 | "version": "1.0.0", 10 | "license": "ISC", 11 | "dependencies": { 12 | "csv-parse": "^5.5.6" 13 | } 14 | }, 15 | "node_modules/csv-parse": { 16 | "version": "5.5.6", 17 | "resolved": "https://registry.npmjs.org/csv-parse/-/csv-parse-5.5.6.tgz", 18 | "integrity": "sha512-uNpm30m/AGSkLxxy7d9yRXpJQFrZzVWLFBkS+6ngPcZkw/5k3L/jjFuj7tVnEpRn+QgmiXr21nDlhCiUK4ij2A==" 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /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 | --------------------------------------------------------------------------------