Implementing math operations in Qualtrics- SOS

跟風遠走 提交于 2019-12-11 15:48:40

问题


I'm new to Qualtrics/JavaScript... would appreciate help on

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]}`

Next, I want to do the following: -find ones in array 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]

Is there a more elegant way to increment that array? Should I set this as embedded data? -multiply difference array by lambda_multiplier

`var mult = multiply(diff_array,lambda_multiplier);`

-then reduce this array to only the non-zero values mult.filter (Boolean)

Am I using the right functions/doing this right?


回答1:


Not sure what you will do with the array mult, but here is code to create it (untested):

    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


来源:https://stackoverflow.com/questions/46537177/implementing-math-operations-in-qualtrics-sos

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!