Can anyone tell me where am I making mistakes here in composition of function problem The question is,
$$ f(x) = \left| x-1 \right| -1 \ , \, x \in [ -1,3] $$
$$ g(x) = 2 - \left| x+1 \right| \ , \, x \in [-2, 2] $$ 
Find $ f(g(x)) $
I did try, but the answer behind the text book has different domain of $f(g(x))$ 
Here's my work, can someone point out the mistake, if any?
https://www.scribd.com/document/384934557/My-work
Thank you :) 
 A: $$g(x) = 2 - \lvert x+1 \rvert, \qquad x \in [-2, 2]$$
So
$$g(x) = 
\begin{cases}
2+(x+1)=x+3, &x\in[-2,-1]\\
2-(x+1)=1-x, &x\in(-1,2]
\end{cases}$$
So
\begin{align}
f(x) 
&= \begin{cases}
\left| x+3-1 \right| -1 =|x+2|-1, &x\in[-2,-1]\\
\left| 1-x-1 \right| -1 =|-x|-1, &x\in(-1,2]
\end{cases} \\
&= \begin{cases}
|x+2|-1, &x\in[-2,-1]\\
|x|-1, &x\in(-1,2]
\end{cases} \\
&= \begin{cases}
(x+2)-1, &x\in[-2,-1]\\
-x-1, &x\in(-1,0]\\
x-1,&x\in(0,2]
\end{cases} \\
&= \begin{cases}
x+1, &x\in[-2,-1]\\
-(x+1), &x\in(-1,0]\\
x-1,&x\in(0,2]
\end{cases} \\
&\text{OR}\\
f(x)&= \begin{cases}
x+1, &x\in[-2,-1)\\
-(x+1), &x\in[-1,0)\\
x-1,&x\in[0,2]
\end{cases} \\
\end{align}
A: If $x \in [-2,2]$ then $0 \leq \lvert x+1 \rvert \leq 3$
and therefore $-1 \leq g(x) \leq 2.$
Since these values of $g(x)$ are all within the domain of $f,$
I conclude that $f(g(x))$ is defined for every $x \in [-2,2].$
The composition $f(g(x))$ cannot be defined for any $x$ that is not in the domain of $g,$ so no other points can be added to the domain.
The domain of $f(g(x))$ therefore is $[-2,2],$
exactly as you concluded.
Moreover, using an online tool to graph $f(g(x))$ confirms the rest of your definition of that function.
It might be helpful to see the book's answer to compare with yours.
