javascript-tutorial / javascript-tutorial/en.javascript.info
Lacking arguments in array.sort()'s compareFn
- Dominant language
- HTML
- Stars
- 25.5k
- Forks
- 4k
- PR merge metrics
- No merged PRs in 30d
Description
Hello, I found this weird usage in test [Shuffle an array](https://javascript.info/array-methods#shuffle-an-array)'s "simple solution":

There is just no arguments in the `array.sort()`'s `compareFn`:
```js
array.sort(() => Math.random() - 0.5);
```
But [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#parameters) says if we use `compareFn`, the arguments of `compareFn` "Will never be undefined.":

According to MDN, the `compareFn` must be used with arguments, i.e.
```js
array.sort((a, b) => Math.random() - 0.5);
```
If it is a typo indeed, please fix it at your convenience, thank you.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the “Shuffle an array” section linked in the issue and search the tutorial source for the shown array.sort() example. Confirm the compareFn wording against the referenced MDN documentation, then update the example if it is a typo and verify that the tutorial displays the corrected snippet.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100