Skip to content

Instantly share code, notes, and snippets.

@BetterProgramming
Created January 6, 2020 22:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BetterProgramming/57b0b73cef289880d34ff95de384f00b to your computer and use it in GitHub Desktop.
Save BetterProgramming/57b0b73cef289880d34ff95de384f00b to your computer and use it in GitHub Desktop.
import React from "react";
export default function Totals({ priceArr, freqInDays, amountToInvest }) {
const numOfDays = priceArr.length;
let coinAmount = 0;
for (let i = 0; i < numOfDays; i += freqInDays) {
const coinValue = priceArr[i][1];
coinAmount += amountToInvest / coinValue;
}
const totalCoinAmount = coinAmount;
const totalInvested = amountToInvest * Math.floor(numOfDays / freqInDays);
const endTotal = totalCoinAmount * priceArr[priceArr.length - 1][1];
const numberGained = endTotal - totalInvested;
const percentGained = ((endTotal - totalInvested) / totalInvested) * 100;
return <div>Totals</div>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment