Let x be the salary. If x is more than the average, we want
If x is less than the average, we want
The two conditions can be summarized into
In fact, the absolute value of the difference of two numbers tells you "how far" those two numbers are, without taking into account which of the two is bigger.