randNumber auto detect fraction
shaharkazaz opened this issue · 4 comments
Description
When using randNumber
with min
& max
options, randNumber
will auto-detect if a fraction is needed.
If the fraction option is passed the function will use that value.
Example
// Current state
randNumber({min: 0.1, max: 1}); // 1, we are not passing the fraction option.
// With auto-detect
randNumber({min: 0.1, max: 1}); // 0.1, 0.2, 0.3, ..., 1
randNumber({min: 0.11, max: 1}); // 0.11, 0.12, 0.13, ..., 1
randNumber({min: 0.1, max: 1, fraction: 3}); // 0.101, 0.102, 0.103, ..., 1
Proposed solution
No response
Alternatives considered
No response
Do you want to create a pull request?
No
I don't think it is possible to implement and it also breaks single responsibility principle.
@czlowiek488 Can you share what makes you think that's not possible to implement?
It's because JavaScript doesn't recognize 1.0
as decimal.
It will not work in all cases.
Also I personally prefer to have one way of achieving something, it makes all users using the same approach and make codebase consistent. Also you don't need to create additional documentation.
@czlowiek488 I agree that this might cause some confusion around this function. The benefits o in some cases doesn't worth the confusing API.