Calculate the vector component
APL (Dyalog Unicode), 1 byteSBCS



⌹


Check all test cases! When used dyadically, X ⌹ Y solves the least squares* system \$Ya = X\$ for a result \$a\$ of the appropriate shape, e.g.:


if \$Y\$ is a matrix and \$X\$ is a vector, we try to solve a linear system of equations.
if \$Y\$ and \$X\$ are matrices, we compute \$Y\$'s (pseudo-)inverse and multiply it on the left of \$X\$.
when both \$X\$ and \$Y\$ are vectors, the least squares formulation reduces to what we want, namely


$$\frac{X \cdot Y}{||Y||^2}$$

*the least squares system \$Ya = X\$ can be understood as "what should \$a\$ be such that \$Ya\$ is as close as can be to \$X\$?", where closeness is measured with the usual L2 distance.