-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Decimal Expansion #787
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
Decimal Expansion #787
Conversation
…raction (decimal or any base from 2 to 10).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggestion: Since you are using a fixed size array as the result, wouldn't is be better to use an object:
{
integer: 3,
decimal: [1, 4, 1, 5],
indexOf: undefined
}
In this particular case, I prefer array vs object, because it left the freedom to name variables when doing destructuring assignments, which is probably better here because this function can return fraction decimals by default, but also bits, trits, octals, etc. Using an object, variables identitifers will always be restricted to the object properties, regardless of the base, which might be more conducive to confusion if the base used is not 10 : Using an array leaves more freedom : This is like hard vs soft code for variable naming/assignment, it encourages the developer to define (meaningful) variables by himself, depending on the situation (btw I realized I refer to decimals regardless of the base in the tests). But if he does not, I agree it is not an advantage at all, eg. in this case :
What's your opinion ? |
I am ok with it, I just feel using an object would be more self explanatory. |
Adding algorithm for representing the decimal expansion of a given fraction a/b using euclidean division. Optionally, the representation can be in binary, ternary, octal, any base from 2 to 10.
Code is compliant with Javascript standard and covered by Jest tests.