Would this method be better using the ternary operator rather than if else?