Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplify chargeDecimalTime #89

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

yankee42
Copy link
Contributor

@yankee42 yankee42 commented Dec 8, 2020

I was idling through the source code and than I found this:

((soc === 100) ? 1 : '0.' + ((soc < 10) ? ('0' + parseInt(soc)) : parseInt(soc)))

I stared at it for a while. Not sure if I may be missing something... But... if the purpose is to divide by 100, then I think I know an algorithm which is a little more compact and should also perform quicker with less memory overhead.

const amountToCharge = capacity - parseFloat(
capacity * ((soc === 100) ? 1 : '0.' + ((soc < 10) ? ('0' + parseInt(soc)) : parseInt(soc)))
).toFixed(2) || 0;
const amountToCharge = capacity * (1 - (soc / 100)) || 0;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant