Skip to content

Instantly share code, notes, and snippets.

@vnegi10
Created May 10, 2024 10:11
Show Gist options
  • Save vnegi10/0081084361d09e5044928c00db8dcbae to your computer and use it in GitHub Desktop.
Save vnegi10/0081084361d09e5044928c00db8dcbae to your computer and use it in GitHub Desktop.
export function getPertChange(breakdown, num_days) {
    const change = (breakdown[breakdown.length - 1].value -
                    breakdown[breakdown.length - 1 - num_days].value)
                    / breakdown[breakdown.length - 1- num_days].value
   
    // Change %
    const pert_change = change * 100;
    // Round off to first digit after decimal
    return Math.round(pert_change * 10) / 10
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment