简体   繁体   English

这个Google脚本有什么问题?

[英]What's wrong with this Google Script?

Basically I'm trying to evaluate 9 different statements and find the smallest absolute value of them. 基本上我正在尝试评估9个不同的语句并找到它们的最小绝对值。 Then, I want to return the NON absolute value of the statement back into the cell. 然后,我想将语句的NON绝对值返回到单元格中。 This is meant to be expanded across cells. 这意味着要跨细胞扩展。 So my input for this is =getCorrectedRotation(E5:5,F5:5,F14:14) 所以我的输入是=getCorrectedRotation(E5:5,F5:5,F14:14)

I'm getting a #REF error. 我收到了#REF错误。 Any ideas? 有任何想法吗?

function getCorrectedRotation(previous, current, step) {
  var r=0,s=0,t=0,u=0,v=0,w=0,x=0,y=0,z=0
  var points = step.length;
  var output = [];
  var i;
  for (i = 0; i < points; i++) {
   r = ((current[i]-previous[i])/step[i])
   s = (((current[i]+360)-previous[i])/step[i])
   t = (((current[i]-360)-previous[i])/step[i])
   u = (((current[i]+360)-(previous[i]+360))/step[i])
   v = (((current[i]+360)-(previous[i]-360))/step[i])
   w = (((current[i]-360)-(previous[i]+360))/step[i])
   x = (((current[i]-360)-(previous[i]-360))/step[i])
   y = ((current[i]-(previous[i]+360))/step[i])
   z = ((current[i]-(previous[i]-360))/step[i])
  switch (Math.min(Math.abs(r),Math.abs(s),Math.abs(t),Math.abs(u),Math.abs(v),Math.abs(w),Math.abs(x),Math.abs(y),Math.abs(z))) {
    case Math.abs(r):
      output.push(r);
      break;
    case Math.abs(s):
      output.push(s);
      break;
    case Math.abs(t):
      output.push(t);
      break;
    case Math.abs(u):
      output.push(u);
      break;
    case Math.abs(v):
      output.push(v);
      break;
    case Math.abs(w):
      output.push(w);
      break;
    case Math.abs(x):
      output.push(x);
      break;
    case Math.abs(y):
      output.push(y);
      break;
    case Math.abs(z):
      output.push(z);
      break;
  }
}
  return output;
}

Seems to me like your reference error is probably the JavaScript equivalent of Java's ArrayIndexOutOfBounds error. 在我看来,你的引用错误可能是Java的ArrayIndexOutOfBounds错误的JavaScript等价物。 I'd try changing 我试着改变

var points = step.length;

to

var points = step.length-1;

and see if that fixes your problem, as most "length" parameters are the number of elements (ie the maximum reference +1). 并查看是否能解决您的问题,因为大多数“长度”参数是元素的数量(即最大参考值+1)。 As is, you're probably just referencing the "last point", which doesn't exist as it's outside the array. 你可能只是引用了“最后一点”,它不存在,因为它在数组之外。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM