Conversation
…raction (decimal or any base from 2 to 10).
raklaptudirm
left a comment
There was a problem hiding this comment.
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.