Skip to content

Commit a5d1937

Browse files
committed
filtering habitable planets
1 parent a4eea8c commit a5d1937

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

Planets/index.js

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const fs = require("fs");
22
const parse = require("csv-parse");
33

4-
const results = [];
4+
const habitablePlanets = [];
55

66
// Note - the file path that has been provided to createReadStream("Planets/kepler_data.csv") is realtive to the package.json file to run the program as `npm run kepler`.
77
// For running the program as `node index.js` in Planets folder, change the path accordingly to createReadStream('kepler_data.csv')
@@ -16,12 +16,24 @@ fs.createReadStream("Planets/kepler_data.csv")
1616
})
1717
)
1818
.on("data", (data) => {
19-
results.push(data); // data will be in json format
19+
if (isHabitablePlanet(data)) {
20+
habitablePlanets.push(data); // data will be in json format
21+
}
2022
})
2123
.on("error", (err) => {
2224
console.error(err);
2325
})
2426
.on("end", () => {
25-
console.log(results);
26-
console.log("Done!");
27+
console.log(habitablePlanets.map((planet) => planet["kepler_name"]));
28+
console.log(`${habitablePlanets.length} habitable planets are found!`);
2729
});
30+
31+
// Filter planets on the basis of how habitable they are
32+
function isHabitablePlanet(planet) {
33+
return (
34+
planet["koi_disposition"] === "CONFIRMED" &&
35+
planet["koi_insol"] > 0.36 &&
36+
planet["koi_insol"] < 1.11 &&
37+
planet["koi_prad"] < 1.6
38+
);
39+
}

0 commit comments

Comments
 (0)