freeCodeCamp Challenge Guide: Vector cross product

Vector cross product


Solutions

Solution 1 (Click to Show/Hide)
function crossProduct(a, b) { 
  if (!a || a.length !== 3 ||
      !b || b.length !== 3)
    return null;
  const c0 = a[1]*b[2] - a[2]*b[1];
  const c1 = a[2]*b[0] - a[0]*b[2];
  const c2 = a[0]*b[1] - a[1]*b[0];
  return [c0, c1, c2];
}