什么'这个谷歌脚本错了

What's wrong with this Google Script?

本文关键字:谷歌 脚本 错了 什么      更新时间:2023-09-26

基本上,我试图评估9个不同的语句,并找到它们的最小绝对值。然后,我想将语句的NON绝对值返回到单元格中。这意味着要在细胞中扩展。所以我的输入是=getCorrectedRotation(E5:5,F5:5,F14:14)

我得到一个#REF错误。有什么想法吗?

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;
}

在我看来,您的引用错误可能相当于Java的ArrayIndexOutOfBounds错误。我会尝试更改

var points = step.length;

var points = step.length-1;

看看这是否解决了你的问题,因为大多数"长度"参数都是元素的数量(即最大引用+1)。实际上,您可能只是在引用"最后一点",因为它在数组之外,所以不存在。