Step 1 :
To factor $ x^{3}+2x^{2}-x-2 $ we can use factoring by grouping:
Group $ \color{blue}{ x^{3} }$ with $ \color{blue}{ 2x^{2} }$ and $ \color{red}{ -x }$ with $ \color{red}{ -2 }$ then factor each group.
$$ \begin{aligned} x^{3}+2x^{2}-x-2 = ( \color{blue}{ x^{3}+2x^{2} } ) + ( \color{red}{ -x-2 }) &= \\ &= \color{blue}{ x^{2}( x+2 )} + \color{red}{ -1( x+2 ) } = \\ &= (x^{2}-1)(x+2) \end{aligned} $$Step 2 :
Rewrite $ x^{2}-1 $ as:
$$ x^{2}-1 = (x)^2 - (1)^2 $$Now we can apply the difference of squares formula.
$$ I^2 - II^2 = (I - II)(I + II) $$After putting $ I = x $ and $ II = 1 $ , we have:
$$ x^{2}-1 = (x)^2 - (1)^2 = ( x-1 ) ( x+1 ) $$