We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ce03607 commit 17b4c98Copy full SHA for 17b4c98
lib/codecept.js
@@ -194,20 +194,15 @@ class Codecept {
194
}
195
196
/**
197
- * Fisher-Yates algorithm for shuffle
+ * Fisher–Yates shuffle (non-mutating)
198
*/
199
- shuffle(arrayToShuffle) {
200
- var i = arrayToShuffle.length,
201
- j,
202
- temp
203
- while (--i > 0) {
204
- j = Math.floor(Math.random() * (i + 1))
205
- temp = arrayToShuffle[j]
206
- arrayToShuffle[j] = arrayToShuffle[i]
207
- arrayToShuffle[i] = temp
+ shuffle(array) {
+ const arr = [...array] // clone to avoid mutating input
+ for (let i = arr.length - 1; i > 0; i--) {
+ const j = Math.floor(Math.random() * (i + 1))
+ ;[arr[i], arr[j]] = [arr[j], arr[i]] // swap
208
209
-
210
- return arrayToShuffle
+ return arr
211
212
213
0 commit comments