An extension theorem on metric spaces Let $(X,d)$ be a metric space and $A$ be a non-empty closed subset of $X$. If $f : A \rightarrow \mathbb{R}$ is a continuous bounded map, then there exists a continuous map $g : X \rightarrow \mathbb{R}$ such that $g(x) = f(x)$ for all $x \in A$, $$\inf_{x \in X}g(x)= \inf_{y \in A}f(y) \hspace{0.6cm} \text{and} \hspace{0.6cm} \sup_{ x \in X}g (x) = \sup_{ y \in A}f(y).$$
I have worked the case when the function is bounded.
Let $m =\inf_{y \in A}f(y) $ and $M= \sup_{ y \in A}f(y)$. In the bounded case, I first assumed that $m=1$ and $M=2$ and proved the theorem for this case. I then used this fact to prove the general case $m<M$. Until here everything worked very well.
My purpose now is to find an extension for $f$ when it is unbounded. To do this, let us consider the homeomorphism $\varphi \colon \mathbb{R} \rightarrow (0,1)$ given by $$\varphi(x) = \tfrac{1}{2} + \tfrac{x}{2( 1+|x|)}$$ Let $h:=\varphi \circ f \colon A \rightarrow (0,1)$. Clearly $h$ is continuous. Now, I need to ensure that $h$ is bounded to use the above case and find an extension $H\colon X \rightarrow (0,1)$ for $h$. So the function $g = \varphi^{-1} \circ H$ would be the desired extension for $f$. How do I apply the previous case when the function is bounded to the application $h$ and obtain the extension $H$?
I need some help to finish this exercise.
 A: I think you are almost there! First, let me shift your $\varphi\colon \mathbb{R} \to (-1, 1)$ by taking $\varphi(x)=x/(1+\lvert x\rvert)$.
We consider an arbitrary continuous function $f\colon A \to \mathbb{R}$, and let $h=\varphi \circ f\colon A \to (-1,1)$. By the first part you already proved, there is a continuous extension $H\colon X \to [-1, 1]$. We want to apply $\varphi^{-1}$, but this is not possible yet, as $H$ might take the values $-1$ and $1$. The basic idea now is to "remove" the points that take these values.
For this, let $B=H^{-1}(\{-1, 1\})=\{x \in X \mid H(x)=1, -1\}$. Note that $B$ is closed (as $H$ is continuous) and disjoint from $A$ (as $H(A)=h(A)\subset (-1, 1)$). By the bounded part (or by Urysohn's Lemma), there is a continuous function $\lambda\colon X \to [0, 1]$ such that $\lambda(a)=1$ for $a \in A$ and $\lambda(b)=0$ for $b \in B$. (*)
Consider now $\tilde{H}=\lambda H\colon X \to [-1, 1]$. Note that $\tilde{H}(a)=1\cdot H(a)=h(a)$ for $a \in A$, and $\tilde{H}(b)=0$ for $b \in B$. And if $x \notin A \cup B$, then $\lvert\tilde{H}(x)\rvert \leq \lvert H(x)\rvert \cdot 1 < 1$ (where the second inequality is from $x \notin B$). This way, $\tilde{H}\colon X \to (-1, 1)$ is a continuous extension of $h$ taking values on $(-1, 1)$.
To conclude, we take $\phi^{-1}\circ\tilde{H}\colon X \to \mathbb{R}$, which is a continuous function extending $\phi^{-1} \circ h=f$ on $A$.

EDIT: Let me expand on (*) If $A, B$ are closed and disjoint in $X$, we can consider the function $\tilde{\lambda}\colon A \cup B \to X$ given by $\tilde{\lambda}(a)=1$ for $a \in A$ and $\tilde{\lambda}(b)=0$ for $b \in B$. This function is well defined (as $A$ and $B$ are disjoint), and is continuous (for instance, you can check it directly from the $\varepsilon-\delta$ definition of continuity, or checking that the preimage of closed is closed). This way, we can apply Urysohn's Lemma to extend $\tilde{\lambda}$ to all of $X$.
A more direct approach is to take $\lambda(x)=d(x, B)/(d(x, A)+d(x, B))$, where $d(x, E)=\inf\{d(x, y) \mid y \in E\}$. The fact that $A$ is closed implies that $d(x, A)=0$ if and only if $x$ is in $A$. Then the fact that $A, B$ are disjoint implies $d(x, A)+d(x, B)0$ for all $x$, so we can divide without trouble.
