How to define such a non-constant, continuous $f(x)$ on $[a,b] \subset \mathbb R$ .. such that for any $c$ on $f(x)$ 's image, there are infinite points $d_i \in [a, b]$ that $f(d_i) = c$?

It's a bit tricky as $[a, b]$ is closed, otherwise $\sin 1/x$ will help...
I will define such $f\colon [-2,2]\to [-2,2]$.
Let $$\tag1f_0(x)=\begin{cases}4x+6&amp;-2\le x\le -1\\
-2x&amp;-1\le x\le 1\\4x-6&amp;1\le x\le 2\end{cases}$$
(which is continuous and attains each value $\in[-2,2]$ at least twice).
Now define recursively
$$\tag2f_{n+1}(x)=\begin{cases}4x+6&amp;-2\le x\le -1\\
1-\frac12f_n(4x+2)&amp;-1\le x\le 0\\
-1-\frac12f_n(4x-2)&amp;0\le x\le 1\\
4x-6&amp;1\le x\le 2\end{cases} $$
By induction on $n$ we see that


$f_n(\pm2)=\pm2$
$f_n$ is a continuous map $[-2,2]\to [-2,2]$
(Not needed, but hints that we are on the right track) For all $c\in [-2,2]$, the set $f_n^{-1}(c)$ has at least $n+2$ elements


Also, for the distance between two functions $f_n$,$f_m$, $n&lt;m$, in this sequence, we find that $$\|f_{n+1}-f_{m+1}\|_\infty\le \frac12\|f_{n}-f_{m}\|_\infty$$ and consequently
$$\|f_n-f_m\|_\infty\le 2^{-n}\|f_0-f_{m-n}\|_\infty\le 4\cdot 2^{-n}. $$
Thus we have a uniformly converging sequence of continuous functions and let $$ f(x)=\lim_{n\to\infty} f_n(x).$$
Then $f$ is a continuous map $[-2,2]\to[-2,2]$ and it is a fixed point under the recursion $(2)$.

Assume that for some $c\in[-2,2]$ the set $f^{-1}(c)$ is finite. Pick $c$ for which this set is minimal. For $0\le c\le 2$ we have
$$f^{-1}(c)\supseteq\left\{\frac{c+6}4\right\}\cup \frac14\bigl(f^{-1}(2-2c)-2\bigr) $$
and the two sets on the right are disjoint because $\frac{c+6}4&gt;0$ and $\frac14\bigl(f^{-1}(2-2c)-2\bigr)\subseteq [-1,0]$. We conclude that 
$$|f^{-1}(2-2c)|\le |f^{-1}(c)|-1 $$
contradicting minimality. A similar argument works for $-2\le c\le 0$.
We conclude that there is no $c\in[-2,2]$ with finite pre-image.
$$
f(x)=
\begin{cases}
x\sin(1/x) &amp; 0&lt;x\leq 1\\
0 &amp; x=0
\end{cases}
$$