You can based in the function argument, as example order parameter, define the operation that you want to do. Put an if to identify if the operation: is shortest do shortest action, if not, do the longest action. It will put some logic, but can help to avoid the function repetition and the same scope can be used.