Congratulations! Your code works correctly and the documentation makes it easy to follow. Cool idea to improve the chooseName() function with boundaries and value checks.
Few remarks:
You could write your lets as consts (always use const when possible)
With the help of the Destructuring Assignment you could write the swapping in one line: [a, b] = [b, a];
The ternary operator could be simplified to: a = a > arr.length ? arr.length - 1 : a; Or, since we do nothing in the else part, a simple if statement would also be possible (matter of taste):
I personally don’t use the JSDoc comment style for functions (/** ... */). I’m neither a fan of “comment everything” nor “the code itself is comment enough”. As a guideline for myself I ask: “Could I immediately understand this code when revisiting some months later?”. If not, I add a comment.
When commenting I always use /* ... */ so they look the same regardless if they are single-line or multi-line.