Skip to content

Commit 8834532

Browse files
committed
add deepCopy warning messages for randomization/sample functions
1 parent 36e64ef commit 8834532

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

docs/reference/jspsych-randomization.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ output:
8989
full_design = {
9090
stimulus: ['a.jpg','b.jpg','b.jpg','a.jpg'],
9191
ms_delay: [200, 100, 200, 100]
92-
]
92+
}
9393
*/
9494
```
9595

@@ -182,6 +182,8 @@ This method takes an array of values and generates a new random order of the arr
182182

183183
If the array elements are objects with the same set of properties, then this method can optionally return a single object where each property is a randomized order of the properties defined in the original set of objects. This is useful for randomizing sets of parameters that are used to define a jsPsych block.
184184

185+
This returns a shallow copy of the array, i.e. modifications to arrays/objects within this array will affect the original. If this is not desired, consider taking a [`deepCopy`](./jspsych-utils.md#jspsychutilsdeepcopy).
186+
185187
### Examples
186188

187189
#### Shuffle an array, no repeats
@@ -414,6 +416,8 @@ An array containing the sample.
414416

415417
This method returns a sample drawn at random from a set of values with replacement. The relative probability of drawing each item can be controlled by specifying the `weights`.
416418

419+
This returns a shallow copy of the array, i.e. modifications to arrays/objects within this array will affect the original. If this is not desired, consider taking a [`deepCopy`](./jspsych-utils.md#jspsychutilsdeepcopy).
420+
417421
### Examples
418422

419423
#### Sample with equal probability
@@ -455,6 +459,8 @@ An array containing the sample.
455459

456460
This method returns a sample drawn at random from a set of values without replacement. The sample size must be less than or equal to the length of the array.
457461

462+
This returns a shallow copy of the array, i.e. modifications to arrays/objects within this array will affect the original. If this is not desired, consider taking a [`deepCopy`](./jspsych-utils.md#jspsychutilsdeepcopy).
463+
458464
### Examples
459465

460466
#### Sample without replacement
@@ -532,6 +538,8 @@ Returns an array with the same elements as the input array in a random order.
532538

533539
A simple method for shuffling the order of an array.
534540

541+
This returns a shallow copy of the array, i.e. modifications to arrays/objects within this array will affect the original. If this is not desired, consider taking a [`deepCopy`](./jspsych-utils.md#jspsychutilsdeepcopy).
542+
535543
### Examples
536544

537545
#### Shuffle an array
@@ -565,6 +573,8 @@ Returns an array with the same elements as the input array in a random order, wi
565573

566574
Shuffle an array, ensuring that neighboring elements in the array are different.
567575

576+
This returns a shallow copy of the array, i.e. modifications to arrays/objects within this array will affect the original. If this is not desired, consider taking a [`deepCopy`](./jspsych-utils.md#jspsychutilsdeepcopy).
577+
568578
*Warning: if you provide an array that has very few valid permutations with no neighboring elements, then this method will fail and cause the browser to hang.*
569579

570580
### Examples

0 commit comments

Comments
 (0)