javascript-tutorial / javascript-tutorial/en.javascript.info
Lacking arguments in array.sort()'s compareFn
- 主要语言
- HTML
- 星标
- 25.5k
- 派生
- 4k
- PR 合并指标
- 30 天内没有已合并 PR
描述
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.
贡献指南
这个仓库没有索引到贡献指南
调研方向
从 issue 中链接的“Shuffle an array”部分开始,在教程源代码中搜索所示的 array.sort() 示例。对照所引用的 MDN 文档确认 compareFn 的措辞,如果示例中存在拼写错误则更新示例,并验证教程显示的是修正后的代码片段。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript
- 领域
- documentation
- Issue 类型
- 文档
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 48/100