Skip to content

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.

@yankee42 yankee42 requested a review from GPlay97 as a code owner December 8, 2020 19:45
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