Merge Sort: review

Hello, I have a question about the very last step of https://www.codecademy.com/paths/pass-the-technical-interview-with-java/tracks/sorting-algorithms-java/modules/merge-sort-java/lessons/merge-sort-java/exercises/review

The instruction is as follows.

In MergeSort.java , we included your code from the last exercise. If you’re up for the challenge, see if you can combine the two lines in your if and else blocks into one line to make your code look a little cleaner.

I need some hints (NOT the solution code though). I am browsing in the Internet and I found out that one could combine multiple “if” lines with switch, enum or other similar solutions. Am I supposed to apply these solutions to this step too?

I can’t see the code because I haven’t completed that lesson yet, though I have in the python course. I’m guessing the ternary operator would be the simplest way to turn it into a one liner. Personally I don’t like ternary operators because I find they make the code harder to read, but that’s just me.

https://www.educative.io/edpresso/what-is-a-ternary-operator-in-java

1 Like