Swap values with structured assignment rather than temporary (#210)

Saves two lines and a variable.

Also, a desperate attempt to save my Mana in https://manifold.markets/ManifoldMarkets/if-we-open-source-our-frontend-code
This commit is contained in:
Jonas Wagner 2022-05-15 07:06:35 +02:00 committed by GitHub
parent 07ded756d9
commit 92aa56ba20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -42,8 +42,6 @@ export function createRNG(seed: string) {
export const shuffle = (array: any[], rand: () => number) => { export const shuffle = (array: any[], rand: () => number) => {
for (let i = 0; i < array.length; i++) { for (let i = 0; i < array.length; i++) {
const swapIndex = Math.floor(rand() * (array.length - i)) const swapIndex = Math.floor(rand() * (array.length - i))
const temp = array[i] ;[array[i], array[swapIndex]] = [array[swapIndex], array[i]]
array[i] = array[swapIndex]
array[swapIndex] = temp
} }
} }