improve implementation and documentation of Ox.divideInt
This commit is contained in:
parent
adb51d67a1
commit
24eb4bdc64
1 changed files with 9 additions and 9 deletions
|
@ -21,23 +21,23 @@ Ox.deg = function(rad) {
|
||||||
|
|
||||||
/*@
|
/*@
|
||||||
Ox.divideInt <f> Divides a number by another and returns an array of integers
|
Ox.divideInt <f> Divides a number by another and returns an array of integers
|
||||||
<code>Ox.divideInt(num, by)</code> returns a sorted array of "as equal as
|
<code>Ox.divideInt(num, by)</code> returns a sorted array of integers that
|
||||||
possible" integers that has a sum of <code>num</code> and a length of
|
has a sum of <code>num</code>, a length of <code>by</code>, a minimum of
|
||||||
<code>by</code>.
|
<code>Math.floor(num / by)</code> and a maximum of
|
||||||
|
<code>Math.ceil(num / by)</code>.
|
||||||
> Ox.divideInt(100, 3)
|
> Ox.divideInt(100, 3)
|
||||||
[33, 33, 34]
|
[33, 33, 34]
|
||||||
> Ox.divideInt(100, 6)
|
> Ox.divideInt(100, 6)
|
||||||
[16, 16, 17, 17, 17, 17]
|
[16, 16, 17, 17, 17, 17]
|
||||||
@*/
|
@*/
|
||||||
|
// fixme: is splitInt a better name?
|
||||||
Ox.divideInt = function(num, by) {
|
Ox.divideInt = function(num, by) {
|
||||||
var arr = [],
|
var div = parseInt(num / by),
|
||||||
div = parseInt(num / by),
|
|
||||||
mod = num % by;
|
mod = num % by;
|
||||||
Ox.loop(by, function(i) {
|
return Ox.range(by).map(function(i) {
|
||||||
arr[i] = div + (i > by - 1 - mod);
|
return div + (i > by - 1 - mod);
|
||||||
});
|
});
|
||||||
return arr;
|
};
|
||||||
}
|
|
||||||
|
|
||||||
/*@
|
/*@
|
||||||
Ox.limit <f> Limits a number by a given mininum and maximum
|
Ox.limit <f> Limits a number by a given mininum and maximum
|
||||||
|
|
Loading…
Reference in a new issue