forked from 0x2620/oxjs
Ox.divideInt -> Ox.splitInt
This commit is contained in:
parent
703003bd2b
commit
f5782c475b
5 changed files with 22 additions and 23 deletions
|
|
@ -50,25 +50,6 @@ Ox.deg = function(rad) {
|
|||
return rad * 180 / Math.PI;
|
||||
};
|
||||
|
||||
/*@
|
||||
Ox.divideInt <f> Divides a number by another and returns an array of integers
|
||||
`Ox.divideInt(num, by)` returns a sorted array of integers that has a sum of
|
||||
`num`, a length of `by`, a minimum of `Math.floor(num / by)` and a maximum
|
||||
of `Math.ceil(num / by)`.
|
||||
> Ox.divideInt(100, 3)
|
||||
[33, 33, 34]
|
||||
> Ox.divideInt(100, 6)
|
||||
[16, 16, 17, 17, 17, 17]
|
||||
@*/
|
||||
// fixme: is splitInt a better name?
|
||||
Ox.divideInt = function(number, by) {
|
||||
var div = Math.floor(number / by),
|
||||
mod = number % by;
|
||||
return Ox.range(by).map(function(i) {
|
||||
return div + (i > by - 1 - mod);
|
||||
});
|
||||
};
|
||||
|
||||
/*@
|
||||
Ox.hypot <f> Returns the square root of the sum of the squares of its arguments
|
||||
(x, y[, z]) -> <n> Square root of the sum of the squares of its arguments
|
||||
|
|
@ -202,6 +183,24 @@ Ox.sinh = function(x) {
|
|||
return (Math.exp(x) - Math.exp(-x)) / 2;
|
||||
};
|
||||
|
||||
/*@
|
||||
Ox.splitInt <f> Splits an integer into an array of integers
|
||||
`Ox.splitInt(num, by)` returns a sorted array of integers that has a sum of
|
||||
`num`, a length of `by`, a minimum of `Math.floor(num / by)` and a maximum
|
||||
of `Math.ceil(num / by)`.
|
||||
> Ox.splitInt(100, 3)
|
||||
[33, 33, 34]
|
||||
> Ox.splitInt(100, 6)
|
||||
[16, 16, 17, 17, 17, 17]
|
||||
@*/
|
||||
Ox.splitInt = function(number, by) {
|
||||
var div = Math.floor(number / by),
|
||||
mod = number % by;
|
||||
return Ox.range(by).map(function(i) {
|
||||
return div + (i > by - 1 - mod);
|
||||
});
|
||||
};
|
||||
|
||||
/*@
|
||||
Ox.tanh <f> Hyperbolic tangent
|
||||
Missing from `Math`.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue