Vector cross product - Simple solution

This is a solution for the specific type of vector supplied in the challenge description

Summary
function crossProduct(a, b) { 
  if(arguments.length == 0) return null
  let cx = a[1]*b[2] - a[2]*b[1]
  let cy = a[2]*b[0] - a[0]*b[2] 
  let cz = a[0]*b[1] - a[1]*b[0] 
  return [cx, cy, cz]
}

Challenge: Vector cross product

Link to the challenge:

1 Like

Slight modification for correctness and style

Summary
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];
}
1 Like

Thank you for your guide post contribution. I have taken your suggestions and included them in the guide post.

We look forward to your further contribution.

1 Like