We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent a4ae1b4 commit 100936eCopy full SHA for 100936e
array-part/README.md
@@ -239,17 +239,14 @@ function unique(arr) {
239
洗牌算法,从最后一个开始随机对换位置。
240
241
```
242
-Array.prototype.shuffle = function() {
243
- var input = this;
244
- for (var i = input.length - 1; i >= 0; i--) {
245
- var randomIndex = Math.floor(Math.random() * (i + 1));
246
- var itemAtIndex = input[randomIndex];
247
-
248
- input[randomIndex] = input[i];
249
- input[i] = itemAtIndex;
250
- }
251
- return input;
252
-};
+Array.prototype.shuffle = function () {
+ const arr = this
+ for (let i = arr.length - 1; i >= 0; i--) {
+ const randomIndex = Math.random() * (i + 1) | 0;
+ [arr[randomIndex], arr[i]] = [arr[i], arr[randomIndex]]
+ }
+ return arr
+}
253
254
255
创建一个长度为100的数组,并且每个元素的值等于它的下标
0 commit comments