(size, direction, currentBin)
| 538 | } |
| 539 | |
| 540 | function cdf(size, direction, currentBin) { |
| 541 | var i, vi, prevSum; |
| 542 | |
| 543 | function firstHalfPoint(i) { |
| 544 | prevSum = size[i]; |
| 545 | size[i] /= 2; |
| 546 | } |
| 547 | |
| 548 | function nextHalfPoint(i) { |
| 549 | vi = size[i]; |
| 550 | size[i] = prevSum + vi / 2; |
| 551 | prevSum += vi; |
| 552 | } |
| 553 | |
| 554 | if(currentBin === 'half') { |
| 555 | if(direction === 'increasing') { |
| 556 | firstHalfPoint(0); |
| 557 | for(i = 1; i < size.length; i++) { |
| 558 | nextHalfPoint(i); |
| 559 | } |
| 560 | } else { |
| 561 | firstHalfPoint(size.length - 1); |
| 562 | for(i = size.length - 2; i >= 0; i--) { |
| 563 | nextHalfPoint(i); |
| 564 | } |
| 565 | } |
| 566 | } else if(direction === 'increasing') { |
| 567 | for(i = 1; i < size.length; i++) { |
| 568 | size[i] += size[i - 1]; |
| 569 | } |
| 570 | |
| 571 | // 'exclude' is identical to 'include' just shifted one bin over |
| 572 | if(currentBin === 'exclude') { |
| 573 | size.unshift(0); |
| 574 | size.pop(); |
| 575 | } |
| 576 | } else { |
| 577 | for(i = size.length - 2; i >= 0; i--) { |
| 578 | size[i] += size[i + 1]; |
| 579 | } |
| 580 | |
| 581 | if(currentBin === 'exclude') { |
| 582 | size.push(0); |
| 583 | size.shift(); |
| 584 | } |
| 585 | } |
| 586 | } |
| 587 | |
| 588 | module.exports = { |
| 589 | calc: calc, |
no test coverage detected