Hello all

I’m converting an experiment from the builder to online, and am working through converting individual code snippets from python to JS in the builder. I’m completely new to JS and so any pointers to help me figure this out would be appreciated.

**My first question is: Is there an easy way to calculate the mean, median and std in JS?**

In the following **python code** I’ve used NumPy to calculate the mean, median and std of the reaction times that are above 0.1 in the practice block-

```
import numpy as np
if trialCount>19:
trials_prac_1.finished = True
# Select RTs that are above 0.1
allRT = trials_prac_1.data['target_prac_1_resp.rt']
selectRT = allRT > 0.1
RT = allRT[selectRT]
# calculate mean RT
meanRT = np.mean(RT)
# calculate median RT
medianRT = np.median(RT)
# define fastest half of the RTs (upper RTs)
upperRT = RT < medianRT
uRT = RT[upperRT]
# calculate mean and std on upper RTs
uppermeanRT = np.mean(uRT)
upperstdRT = np.std(uRT)
# calculate minimum and maximum duration of the target
minmax = upperstdRT*2
trials_prac_1.addData('upperRT', upperRT)
trials_prac_1.addData('minmax', minmax)
```

Here’s the **JS code** I’ve converted so far but am stuck with calculating the mean, median and std-

```
if (trialCount > 19) {
trials_prac_1.finished = true;
}
# Select RTs that are above 0.1
allRT = trials_prac_1.data['target_prac_1_resp.rt'];
selectRT = allRT > 0.1;
RT = allRT[selectRT];
# calculate mean RT
# calculate median RT
# define fastest half of the RTs (upper RTs)
upperRT = RT < medianRT;
uRT = RT[upperRT];
# calculate mean and std on upper RTs
# calculate minimum and maximum duration of the target
minmax = upperstdRT*2;
trials_prac_1.addData('upperRT', upperRT);
trials_prac_1.addData('minmax', minmax);
```

Subsequently in the task, the variables meanRT and minmax are used to calculate the duration of a target using the random.normal function in the following **python code**:

```
target_duration = np.random.normal(loc = meanRT, scale = minmax)
```

**And so my second question is: Is there an equivalent of np.random.normal that I can use in JS?**

Any pointers would be much appreciated and thanks very much for your time

Rachel