javascript-tutorial / javascript-tutorial/en.javascript.info
Lacking arguments in array.sort()'s compareFn
- Ngôn ngữ chính
- HTML
- Star
- 25.5k
- Fork
- 4k
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
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.
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Hướng nghiên cứu
Bắt đầu với phần “Shuffle an array” được liên kết trong issue và tìm trong mã nguồn của tutorial ví dụ array.sort() được hiển thị. Đối chiếu cách diễn đạt về compareFn với tài liệu MDN được tham chiếu, sau đó cập nhật ví dụ nếu đó là lỗi đánh máy và xác minh rằng tutorial hiển thị snippet đã được sửa.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- javascript
- Lĩnh vực
- documentation
- Loại issue
- Tài liệu
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 48/100