Skip to content

Instantly share code, notes, and snippets.

@Rinlama
Created June 27, 2021 19:44
Show Gist options
  • Select an option

  • Save Rinlama/402ff8111db4e2df3533a84f7055b6ee to your computer and use it in GitHub Desktop.

Select an option

Save Rinlama/402ff8111db4e2df3533a84f7055b6ee to your computer and use it in GitHub Desktop.
Address|City|State|ZipCode|Date|Price|RehabCost|TotalCost|PriceSold|NetIncome
314 -ARBOUR|Newark|DE|19713|08/12/14|"166,000.00"|"17,092.07"|"183,092.07"|"250,000.00" | $66,907.93 |
119 S.-KINGS|Bear|DE|19701|09/10/14|"157,000.00"|"208,543.20"|"365,543.20"|"228,377.00" | -$137,166.20 |
400-BRENNEN|Newark|DE|19713|10/14/14|"123,000.00"|"142,370.73"|"265,370.73"|"183,300.00" | -$82,070.73 |
114 SONAN|Newark|DE|19713|10/14/14|"157,000.00"|"63,127.35"|"220,127.35"|"209,999.00" | -$10,128.35 |
206 BEAVER|Bear|DE|19701|10/14/14|"72,000.00"|"54,432.30"|"126,432.30"|"111,300.00" | -$15,132.30 |
37 SPRING LAKE|Newark|DE|19711|11/12/14|"122,401.00"|0.00|"122,401.00"|"128,401.00" | $6,000.00 |
28-COURT|Newark|DE|19702|10/14/14|"79,000.00"|"7,900.00"|"86,900.00"|"86,000.00" | -$900.00 |
404 Mansion|Wilmington|DE|19804|11/12/14|"104,000.00"|"192,914.97"|"296,914.97"|"118,214.00" | -$178,700.97 |
38 Gershwin|New Castle|DE|19720|04/10/14|"104,000.00"|"173,404.37"|"277,404.37"|"168,059.00" | -$109,345.37 |
a. Net Income
i. This value is calculated as (Price Sold – Total Cost)
const fs = require("fs");
const readline = require("readline");
const os = require("os");
const fileStream = fs.createReadStream("./Prop.txt");
function calculate() {
fs.writeFile("./answer.txt", "", () => {
console.log("Empty file .....");
});
const rl = readline.createInterface({
input: fileStream,
});
let counter = 0;
rl.on("line", (res) => {
if (counter != 0) {
const eachline = res.split("|");
var totalcost = eachline[7].replace(/[$,]+/g, "").replace(/['"]+/g, "");
var pricesold = eachline[8].replace(/[$,]+/g, "").replace(/['"]+/g, "");
const netIncome = parseFloat(pricesold) - parseFloat(totalcost);
const curr = new Intl.NumberFormat("en-US", {
style: "currency",
currency: "USD",
}).format(netIncome);
const secondlastIndexOf = res.lastIndexOf("|") - 1;
const answer = `${res.substring(0, secondlastIndexOf)} | ${curr} | ${
os.EOL
}`;
appendText(answer)
.then((d) => {
console.log(d);
})
.catch((error) => {
console.error(err);
});
}
if (counter === 0) {
appendText(res + os.EOL)
.then((d) => {
console.log(d);
})
.catch((error) => {
console.error(err);
});
}
counter++;
});
}
const appendText = (data) => {
return new Promise((resolve, reject) => {
fs.appendFile("./answer.txt", data, "utf8", (err) => {
resolve("added file ");
if (err) reject(err);
});
});
};
calculate();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment