我是Qualtrics / JavaScript的新手......希望得到帮助
Var block1= [parseInt("${q://QID664/SelectedAnswerRecode/1}"), parseInt("${q://QID664/SelectedAnswerRecode/2}"), parseInt("${q://QID664/SelectedAnswerRecode/3}"), parseInt("${q://QID664/SelectedAnswerRecode/4}"), parseInt("${q://QID664/SelectedAnswerRecode/5}"), parseInt("${q://QID664/SelectedAnswerRecode/6}"), parseInt("${q://QID664/SelectedAnswerRecode/7}"), parseInt("${q://QID664/SelectedAnswerRecode/8}"), parseInt("${q://QID664/SelectedAnswerRecode/9}"), parseInt("${q://QID664/SelectedAnswerRecode/10}")];
`for(i=0;i<block1.length;i++) {
`diff_array[i]= block1[i+1]- block1[i]}`
接下来,我想要做以下事情:
- 找到数组
num_switch_block1= number of ones in difference array)
-create lambda variable-
lambda_multiplier= [.7, .9, 1.1, 1.3, 1.5, 1.7, 1.9, 2.1, 2.3]
是否有更优雅的方法来增加该数组?我应该将其设置为嵌入数据吗? - lambda_multiplier的多重差分数组
`var mult = multiply(diff_array,lambda_multiplier);`
- 然后将此数组仅减少为非零值
mult.filter (Boolean)
我使用正确的功能/这样做吗?
答案 0 :(得分:1)
不确定你将对数组mult做什么,但这里是创建它的代码(未经测试):
var block1= [parseInt("${q://QID664/SelectedAnswerRecode/1}"),
parseInt("${q://QID664/SelectedAnswerRecode/2}"),
parseInt("${q://QID664/SelectedAnswerRecode/3}"),
parseInt("${q://QID664/SelectedAnswerRecode/4}"),
parseInt("${q://QID664/SelectedAnswerRecode/5}"),
parseInt("${q://QID664/SelectedAnswerRecode/6}"),
parseInt("${q://QID664/SelectedAnswerRecode/7}"),
parseInt("${q://QID664/SelectedAnswerRecode/8}"),
parseInt("${q://QID664/SelectedAnswerRecode/9}"),
parseInt("${q://QID664/SelectedAnswerRecode/10}")];
var lambda_multiplier = [.7, .9, 1.1, 1.3, 1.5, 1.7, 1.9, 2.1, 2.3];
var mult = [];
for(i=0;i<lambda_multiplier.length;i++) {
mult[i] = (block1[i+1] - block1[i]) * lambda_multiplier[i];
}
mult = mult.filter(Number); //remove 0s from mult