You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/reference/jspsych-randomization.md
+11-1Lines changed: 11 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -89,7 +89,7 @@ output:
89
89
full_design = {
90
90
stimulus: ['a.jpg','b.jpg','b.jpg','a.jpg'],
91
91
ms_delay: [200, 100, 200, 100]
92
-
]
92
+
}
93
93
*/
94
94
```
95
95
@@ -182,6 +182,8 @@ This method takes an array of values and generates a new random order of the arr
182
182
183
183
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.
184
184
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
+
185
187
### Examples
186
188
187
189
#### Shuffle an array, no repeats
@@ -414,6 +416,8 @@ An array containing the sample.
414
416
415
417
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`.
416
418
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
+
417
421
### Examples
418
422
419
423
#### Sample with equal probability
@@ -455,6 +459,8 @@ An array containing the sample.
455
459
456
460
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.
457
461
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
+
458
464
### Examples
459
465
460
466
#### Sample without replacement
@@ -532,6 +538,8 @@ Returns an array with the same elements as the input array in a random order.
532
538
533
539
A simple method for shuffling the order of an array.
534
540
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
+
535
543
### Examples
536
544
537
545
#### Shuffle an array
@@ -565,6 +573,8 @@ Returns an array with the same elements as the input array in a random order, wi
565
573
566
574
Shuffle an array, ensuring that neighboring elements in the array are different.
567
575
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
+
568
578
*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.*
| object | Object or Array | An arbitrary object or array |
46
+
47
+
### Return value
48
+
49
+
A deep copy of the provided object or array
50
+
51
+
### Description
52
+
53
+
This function takes an arbitrary object or array and returns a deep copy of it, i.e. all child objects or arrays are recursively copied too.
54
+
55
+
### Example
56
+
57
+
```javascript
58
+
var myObject = { nested: ["array", "of", "elements"] };
59
+
var deepCopy =jsPsych.utils.deepCopy(myObject);
60
+
deepCopy.nested[2] ="thingies";
61
+
console.log(myObject.nested[2]) // still logs "elements"
62
+
```
63
+
64
+
---
65
+
66
+
## jsPsych.utils.deepMerge
67
+
68
+
```javascript
69
+
jsPsych.utils.deepMerge(object1, object2);
70
+
```
71
+
72
+
### Parameters
73
+
74
+
| Parameter | Type | Description |
75
+
| --------- | ------ | --------------- |
76
+
| object1 | Object | Object to merge |
77
+
| object2 | Object | Object to merge |
78
+
79
+
### Return value
80
+
81
+
A deep copy of `object1` with all the (nested) properties from `object2` filled in
82
+
83
+
### Description
84
+
85
+
This function takes two objects and recursively merges them into a new object. If both objects define the same (nested) property, the property value from `object2` takes precedence.
0 commit comments