Drawing a picture helps. f(x)=2 is a line parallel to and above the x axis which has a right-hand end-point at x=-1, so it stretches from from minus infinity to -1. f(x)=-2 is a similar line below the x axis extending to plus infinity from x=3, its left-hand end-point. We can join the end-points of the two lines using f(x)=ax+b, where a is the slope and b the y intercept. We know for continuity that the end-points (-1,2) and (3,-2) must lie on the line, so we can write:
2=-a+b and -2=3a+b. From the first equation b=a+2, so put this into the second equation: -2=3a+a+2, 4a=-4 and a=-1, making b=-1+2=1, and f(x)=-x+1 or 1-x. This line segment joins the other lines between the required limits, providing continuity.