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