by codeflo · 12y ago · 0 comments
function make_dot_product(dim) {
var dot;
if (dim === 3) {
dot = function(a, b) {
return a.x * b.x + a.y * b.y + a.z * b.z;
};
} else if (dim === 2) {
dot = function(a, b) {
return a.x * b.x + a.y * b.y;
};
}
return dot;
}
This also makes it clearer what happens if neither dim is neither 2 nor 3.That said, it is cleaner to only 'var' each variable once, to suppress this confusion.