Question:
Find the maximum value of $f(x)=\frac{|x|-2-x^2}{|x|+1},x\in\mathrm R$
My Attempt:
I took two cases. One where $x\ge0$, so, $|x|=x$ and another where $x\le0$, so, $|x|=-x$. Then I cross multiplied, made a quadratic in $x$ and wrote discriminant greater than equal to zero. Accordingly, I got range of $f(x)$.
I wonder if there is another way to solve this question, where we don't have to take two cases.

Let $t=|x|+1\geq 1$, then $$\frac{|x|-2-x^2}{|x|+1}=\frac{t-1-2-(t-1)^2}t=\frac{-t^2+3t-4}t=3-\left(t+\frac4t\right).$$ By AM-GM, $t+\frac4t\geq 2\sqrt{t\cdot \frac4t}=4$, with equality iff $t=2$, which is allowed here (recall that we have $t\geq1$). So $$f(x)=\frac{|x|-2-x^2}{|x|+1}= 3-\left(t+\frac4t\right)\leq 3-4=-1,$$ where the equality holds iff $t=2$, i.e., iff $|x|=1$. Therefore, the maximum is $f(-1)=f(1)=-1$.