Skip to content

Commit

Permalink
fix(generateRanges): avoid any infinite loop. Fix #351
Browse files Browse the repository at this point in the history
  • Loading branch information
redox committed Oct 26, 2015
1 parent 52e5d81 commit 4965222
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion widgets/price-ranges/__tests__/generate-ranges-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('generateRanges()', () => {
expect(generateRanges(stats)).toEqual(expected);
});

it.only('should not do an infinite loop', () => {
it('should not do an infinite loop', () => {
var stats = {min: 99.99, max: 149.99, avg: 124.99, sum: 249.98};
generateRanges(stats);
});
Expand Down
7 changes: 6 additions & 1 deletion widgets/price-ranges/generate-ranges.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,20 @@ function generateRanges(stats) {
while (next < avg) {
from = facetValues[facetValues.length - 1].to;
next = round(from + (avg - min) / 3, precision);
if (next <= from) {
next = from + 1;
}
facetValues.push({
from: from,
to: next
});
}
while (next < max) {
console.log('YOLO LOOP')
from = facetValues[facetValues.length - 1].to;
next = round(from + (max - avg) / 3, precision);
if (next <= from) {
next = from + 1;
}
facetValues.push({
from: from,
to: next
Expand Down

0 comments on commit 4965222

Please sign in to comment.