Dollar cost average / investment calculator
been struggling pretty bad with this component, really knocked some confidence out of me 😅😬
When I enter the dates and other inputs and click calculate, it does work (shows the correct amount spent and total investment value). But if I then change the finish date and click calculate again, it shows a very low number (or sometimes 0) for the total value. So it works the first time but not after that.
I think the problem lies in this piece of code which is inside the getTotalVal function:
const purchaseDateObjects = priceData.filter((priceObj) => {
return dates.some(
(date) =>
new Date(date).toISOString().split("T")[0] ===
priceObj.date.toISOString().split("T")[0]
);
});
after changing the finish date, purchaseDateObjects ends up having only a small number of dates in it, missing a lot of them. Or sometimes its just empty, resulting in totalCoinHolding = either an incorrect / low figure or 0.
If I just change the start date there are no problems, just happens with the finish date.
Appreciate any input thanks.
2
1 comment
Ryan Hazlewood
5
Dollar cost average / investment calculator
Developer Pro
skool.com/developerpro
Learn how to code. Make money. Have fun. Enjoy life.
Leaderboard (30-day)
powered by