Math.min(windowWidth - 1, Math.max(prediction, -windowWidth + 1));

Not sure this is much more readable though.