Skip to content

Commit b202d61

Browse files
authored
Update solution.md
1 parent 24411a8 commit b202d61

File tree

1 file changed

+8
-8
lines changed
  • 1-js/05-data-types/05-array-methods/9-shuffle

1 file changed

+8
-8
lines changed

1-js/05-data-types/05-array-methods/9-shuffle/solution.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ let count = {
3333
'312': 0
3434
};
3535

36-
for(let i = 0; i < 1000000; i++) {
36+
for (let i = 0; i < 1000000; i++) {
3737
let array = [1, 2, 3];
3838
shuffle(array);
3939
count[array.join('')]++;
4040
}
4141

4242
// show counts of all possible permutations
43-
for(let key in count) {
43+
for (let key in count) {
4444
alert(`${key}: ${count[key]}`);
4545
}
4646
```
@@ -66,8 +66,8 @@ There are other good ways to do the task. For instance, there's a great algorith
6666

6767
```js
6868
function shuffle(array) {
69-
for(let i = array.length - 1; i > 0; i--) {
70-
let j = Math.floor(Math.random() * (i+1)); // random index from 0 to i
69+
for (let i = array.length - 1; i > 0; i--) {
70+
let j = Math.floor(Math.random() * (i + 1)); // random index from 0 to i
7171
[array[i], array[j]] = [array[j], array[i]]; // swap elements
7272
}
7373
}
@@ -77,8 +77,8 @@ Let's test it the same way:
7777

7878
```js run
7979
function shuffle(array) {
80-
for(let i = array.length - 1; i > 0; i--) {
81-
let j = Math.floor(Math.random() * (i+1));
80+
for (let i = array.length - 1; i > 0; i--) {
81+
let j = Math.floor(Math.random() * (i + 1));
8282
[array[i], array[j]] = [array[j], array[i]];
8383
}
8484
}
@@ -93,14 +93,14 @@ let count = {
9393
'312': 0
9494
};
9595

96-
for(let i = 0; i < 1000000; i++) {
96+
for (let i = 0; i < 1000000; i++) {
9797
let array = [1, 2, 3];
9898
shuffle(array);
9999
count[array.join('')]++;
100100
}
101101

102102
// show counts of all possible permutations
103-
for(let key in count) {
103+
for (let key in count) {
104104
alert(`${key}: ${count[key]}`);
105105
}
106106
```

0 commit comments

Comments
 (0)