Merge pull request #203 from andreasvirkus/patch-1

Fix reduce warning for empty arrays
This commit is contained in:
Shivam Mishra 2019-08-11 21:18:47 +05:30 committed by GitHub
commit 884c52c671
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -212,7 +212,7 @@ export function isInRange2D(coord, minCoord, maxCoord) {
export function getClosestInArray(goal, arr, index = false) {
let closest = arr.reduce(function(prev, curr) {
return (Math.abs(curr - goal) < Math.abs(prev - goal) ? curr : prev);
});
}, []);
return index ? arr.indexOf(closest) : closest;
}