fixes
This commit is contained in:
parent
7fd3eb1797
commit
d94b2922dc
16 changed files with 218 additions and 180 deletions
|
@ -68,7 +68,13 @@ There are other good ways to do the task. For instance, there's a great algorith
|
|||
function shuffle(array) {
|
||||
for (let i = array.length - 1; i > 0; i--) {
|
||||
let j = Math.floor(Math.random() * (i + 1)); // random index from 0 to i
|
||||
[array[i], array[j]] = [array[j], array[i]]; // swap elements
|
||||
|
||||
// swap elements array[i] and array[j]
|
||||
// we use "destructuring assignment" syntax to achieve that
|
||||
// you'll find more details about that syntax in later chapters
|
||||
// same can be written as:
|
||||
// let t = array[i]; array[i] = array[j]; array[j] = t
|
||||
[array[i], array[j]] = [array[j], array[i]];
|
||||
}
|
||||
}
|
||||
```
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue