Skip to content

Commit 54aa7a9

Browse files
committed
fix(stackPrefetch.js): Prevent undefined imageId prefetch
Change the prefetch nearest range to always return valid indices
1 parent 6f9887e commit 54aa7a9

File tree

2 files changed

+8
-20
lines changed

2 files changed

+8
-20
lines changed

src/stackTools/stackPrefetch.js

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,32 +40,20 @@ function range(lowEnd, highEnd) {
4040
return arr;
4141
}
4242

43-
const max = function(arr) {
44-
return Math.max.apply(null, arr);
45-
};
46-
47-
const min = function(arr) {
48-
return Math.min.apply(null, arr);
49-
};
50-
5143
function nearestIndex(arr, x) {
5244
// Return index of nearest values in array
5345
// http://stackoverflow.com/questions/25854212/return-index-of-nearest-values-in-an-array
54-
const l = [];
55-
const h = [];
56-
57-
arr.forEach(function(v) {
46+
let low = 0;
47+
let high = arr.length - 1;
48+
arr.forEach((v, idx) => {
5849
if (v < x) {
59-
l.push(v);
50+
low = Math.max(idx, low);
6051
} else if (v > x) {
61-
h.push(v);
52+
high = Math.min(idx, high);
6253
}
6354
});
6455

65-
return {
66-
low: arr.indexOf(max(l)),
67-
high: arr.indexOf(min(h)),
68-
};
56+
return { low, high };
6957
}
7058

7159
function prefetch(element) {

src/util/uuidv4.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export default function uuidv4() {
22
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
3-
let r = (Math.random() * 16) | 0,
4-
v = c == 'x' ? r : (r & 0x3) | 0x8;
3+
const r = (Math.random() * 16) | 0; // eslint-disable-line no-bitwise
4+
const v = c === 'x' ? r : (r & 0x3) | 0x8; // eslint-disable-line no-bitwise
55

66
return v.toString(16);
77
});

0 commit comments

Comments
 (0)