Ad

Short-circuit operator

The code change replaced a ternary operator with a short-circuit operator. The function reverseGear now returns the reversed string, or an empty string if the input is empty or contains only one character. The change makes the code more concise while retaining the same functionality.

Code
Diff
  • const reverseGear = word => reverseString(word.substr(1)) + word.charAt(0) || ""
    • const reverseGear = word => word === "" ? "" : reverseString(word.substr(1)) + word.charAt(0)
    • const reverseGear = word => reverseString(word.substr(1)) + word.charAt(0) || ""