Skip to content

Commit 4965222

Browse files
committed
fix(generateRanges): avoid any infinite loop. Fix #351
1 parent 52e5d81 commit 4965222

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

widgets/price-ranges/__tests__/generate-ranges-test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe('generateRanges()', () => {
3939
expect(generateRanges(stats)).toEqual(expected);
4040
});
4141

42-
it.only('should not do an infinite loop', () => {
42+
it('should not do an infinite loop', () => {
4343
var stats = {min: 99.99, max: 149.99, avg: 124.99, sum: 249.98};
4444
generateRanges(stats);
4545
});

widgets/price-ranges/generate-ranges.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,20 @@ function generateRanges(stats) {
3333
while (next < avg) {
3434
from = facetValues[facetValues.length - 1].to;
3535
next = round(from + (avg - min) / 3, precision);
36+
if (next <= from) {
37+
next = from + 1;
38+
}
3639
facetValues.push({
3740
from: from,
3841
to: next
3942
});
4043
}
4144
while (next < max) {
42-
console.log('YOLO LOOP')
4345
from = facetValues[facetValues.length - 1].to;
4446
next = round(from + (max - avg) / 3, precision);
47+
if (next <= from) {
48+
next = from + 1;
49+
}
4550
facetValues.push({
4651
from: from,
4752
to: next

0 commit comments

Comments
 (0)