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...
 A: I will define such $f\colon [-2,2]\to [-2,2]$.
Let $$\tag1f_0(x)=\begin{cases}4x+6&-2\le x\le -1\\
-2x&-1\le x\le 1\\4x-6&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&-2\le x\le -1\\
1-\frac12f_n(4x+2)&-1\le x\le 0\\
-1-\frac12f_n(4x-2)&0\le x\le 1\\
4x-6&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<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>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.
A: The Cantor's function is constant on an open dense set of $[0,1]$, and $f^{-1}(x)$ is an interval for $x=\frac a {2^b} \in [0,1]$. We could slightly change it in order to have the infinite preimage property for all $x \in [0,1]$. We can replace the constant parts $y=c$ with a sinusoidal function $c+b\sin(a x)$ in order to have a single complete oscillation on the interval with amplitude $b=2^{-k}$ at the $k^{\text{th}}$ step. This amplitude allows to realize at every stage $k$ the conditions:


*

*$f_k([0,1])=[0,1]$ 

*every $x$ has at least $k$ preimages. 


The convergence would follow just like that of the original Cantor's function.
A: $$
f(x)=
\begin{cases}
x\sin(1/x) & 0<x\leq 1\\
0 & x=0
\end{cases}
$$
