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:
parent
07ded756d9
commit
92aa56ba20
|
@ -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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user