Solution (source code)

= Solution

Choose the <image of a function> as a $j$-element <subset> of $B$, then choose a <surjection> onto that selected image as in (iii). Therefore
$$
\boxed{\#\{f:A\to B:|\operatorname{Im}f|=j\}=\binom nj j!S(m,j)\quad(0\leq j\leq\min(m,n)).}
$$
The answer is zero when $j>n$. If $j=0$, it is one for $m=0$ and zero for $m>0$, as the <Stirling numbers of the second kind> conventions require.