-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstimdevi.js
More file actions
94 lines (61 loc) · 2 KB
/
Copy pathstimdevi.js
File metadata and controls
94 lines (61 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
export function stimdeviset(type,numtrials)
{
//CODE TO SHUFFLE ARRAY
function shuffle(array)
{
var currentIndex = array.length, temporaryValue, randomIndex;
// While there remain elements to shuffle...
while (0 !== currentIndex) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
// And swap it with the current element.
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
}
//CODE TO REPLICATE ARRAY
function repeatArray(arr, count) {
var ln = arr.length;
var b = [];
for(i=0; i<count; i++) {
b.push(arr[i%ln]);
}
return b;
}
function fillArray(value, len)
{
var arr = [];
for(var t = 0; t < value.length; t++)
{
for (var i = 0; i < len; i++)
{
arr.push(value[t]);
}
}
return arr;
}
if (type == 'prac')
{
//the stim position
pracstimpos= fillArray([1,2], (numtrials/2));
pracpos = shuffle(pracstimpos);
return pracpos;
}
else if (type == 'trial')
{
stimpos1= fillArray([1,2], (numtrials/2));
//finally shuffle all these arrays horizontally, but not vertically (i.e. not to mess up the association between conf and acc)
len = stimpos1.length; //length (i.e. number of trials)
perm = shuffle(Array.from({length: len}, (_, index) => index));//get shuffled order of array 0:ntrials
stimpos2 = []
for (var j = 0; j < len; j++) {
stimpos2[j] = stimpos1[perm[j]]
}
return stimpos1;
return stimpos2;
return perm;
}
}