Continuous mapping from a nowhere dense set to dense set Let $X$ be a complete metric space, $B$ be a (closed) nowhere dense set in $X$, $f:B\rightarrow X$ be a continuous mapping. Is it possible that $f(B)$ is dense in $X$?
I think that is possible. But I can't give a counter-example. Any help will be appreciated.
 A: $\textbf{Theorem}$: Every compact metric space is a continuous image of the Cantor set $\mathcal{C}$. (See here)
Let us consider the set $[0, 1]$ as euclidean subspace of $(\Bbb{R}, d_{\text{std}}) $.
Then there there exists a continuous onto function $f:\mathcal{C} \to [0, 1]$.
Now $\mathcal{C}\subset [0,1]$ is closed nowhere dense but $f(\mathcal{C})=[0, 1]$ which is a trivial dense subset of $[0,1]$.
Note: $f$ is here the restriction of the cantor function on the cantor set $\mathcal{C}$.
A: Since $B$ is nowhere dense, it inherits the discrete topology from $X$, which means that any function from $B$ will be continuous. Thus any surjection from $\mathbb{Z}$ onto $\mathbb{Q}$ serves as an example.
But we can do better than this. It is actually possible for $f$ to be continuous on all of $X$, with $f(B)$ still dense! Let $X$ be the positive reals, with $f(x)=x\sin(x)$. Define $$B = \bigcup_{n \in \mathbb{N}} \{2\pi n^3 + \sin^{-1}(\frac{k}{n^4}): k \in \mathbb{N}, k < n^2\}. $$ One can see that $B$ is nowhere dense: every interval of length $2\pi$ contains only finitely many points of $B$. To show $f(B)$ is dense, we need to construct a $b \in B$ with $|b\sin(b) - x| < \epsilon$ for any arbitrary $x, \epsilon > 0$. For large $n$, we have that $\frac{1}{n^2} < \frac{\epsilon}{2}$. For larger $n$, there is some integer $k$ for which $|\frac{2\pi k}{n} - x| < \frac{\epsilon}{2}$. For still larger $n$, we also can guarantee that $k < n^2$.
Therefore $B$ contains the point $b = 2\pi n^3 + \sin^{-1}(\frac{k}{n^4})$. Now, $f(b) = b \sin(b) = b \cdot \frac{k}{n^4} = \frac{2\pi k}{n} + \frac{k}{n^4}\sin^{-1}(\frac{k}{n^4})$. Thus,
$$ |b - x| 
= \bigg| \frac{2\pi k}{n} + \frac{k}{n^4}\sin^{-1}(\frac{k}{n^4}) - x \bigg| 
\leq \bigg| \frac{2\pi k}{n} - x\bigg| + \bigg|\frac{k}{n^4}\sin^{-1}(\frac{k}{n^4}) \bigg|. $$
The first term is less than $\frac{\epsilon}{2}$ by choice of $k$. The second term is also less than $\frac{\epsilon}{2}$, because $\sin^{-1}(\frac{k}{n^4})$ is bounded by 1, and $\frac{k}{n^4} < \frac{n^2}{n^4} = \frac{1}{n^2} < \frac{\epsilon}{2}$. Therefore $|b - x| < \epsilon$.
There are probably better examples than this. This related post offers a hypothesis which, if true, would give a far more elegant example.
A: Any space-filling curve gives you an example of a continuous surjective map
$$
B=[0,1]\subset X=[0,1]^2\to X.
$$
Actually, this situation is quite generic. As long as your metric space $X$ is, say, compact, and contains a nowhere dense subset $B$ homeomorphic to the Cantor set, you get continuous surjective map $B\to X$. (This is a theorem due to Hausdorff.)
