- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我毫不怀疑我自己的白痴对此负责。我不是程序员,而是科学家,而且我通常只是对某些东西进行破解,直到它起作用为止,这就是我最终遇到这些奇怪错误的原因。基本上,我们将不胜感激任何帮助。
好的,所以我的功能是这样的:
function discardDuplicates(threshold) {
for (var m = 0; m < xCo2.length; m++){
var testX = xCo2[m];
var testY = yCo2[m];
for (var n = 0; n < xCo2.length; n++){
if (m != n) {
if ((Math.abs(xCo2[n] - testX) < threshold)
&& (Math.abs(yCo2[n] - testY) < threshold)
&& deltas[m] > deltas[n]){
xCo2.splice(n,1);
yCo2.splice(n,1);
deltas.splice(n,1);
}
}
}
}
}
我正在检测坐标 (x,y) 存储在 xCo2 和 yCo2 数组中的特征,每个坐标也有一个称为“delta”的属性。我想检查一下我是否在基本相同的地方确定了几个特征——如果我有,它们可能是重复的,所以我从列表中删除除了具有最高 delta 的那个之外的所有特征。
对,基本上,这是行不通的!
目前我必须这样做:
//ugly hack
var oldLength = 0;
var newLength = 1;
while (oldLength != newLength) {
oldLength = xCo2.length;
discardDuplicates(10);
newLength = xCo2.length;
}
因为第一次调用该函数时它不会删除任何重复项。第二次它删除了其中的大部分。第三次它通常都有它们......所以我只是继续调用它直到它停止删除重复项。该功能确实有效;它正在删除正确的点。
我问这个问题的原因是,同样的错误现在已经第二次发生,第二个函数,这次试图删除任何增量值太低的坐标。
启蒙将被感激地接受!
最佳答案
在数组上调用 splice
将删除一个条目并将下一个条目移动到该位置,这是非常常见的错误。
让我们来看看:
xCo2 = [1, 2, 3, 4, 5];
n = 0;
xCo2.splice(n, 1); // n = 0, removed 1
>> [2, 3, 4, 5];
n ++;
xCo2.splice(n, 1); // n = 1, removed 3
>> [2, 4, 5];
n++;
看到问题了吗?您正在跳过条目,您需要做的是每次从数组中删除条目时减少 n
。由于您总是删除 1 个条目,因此在拼接数组后需要将 n 减少一次。
if ((Math.abs(xCo2[n] - testX) < threshold)
&& (Math.abs(yCo2[n] - testY) < threshold) && deltas[m] > deltas[n] ){
xCo2.splice(n,1);
yCo2.splice(n,1);
deltas.splice(n,1);
n--;
}
PS:一些空格会大大提高代码的可读性。
关于javascript - 荒谬的 JavaScript 错误 : have to call a function multiple times for it to behave correctly,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4239348/
我有一个行为场景大纲,我需要在其中使用竖线字符 - | 作为示例表中的单元格值。但我不知道如何转义这个字符而不被视为列分隔符。当我尝试使用 \| 序列时,出现了 Malformed table 错误。
这个示例代码有效(我可以在文件中写一些东西): from multiprocessing import Process, Queue queue = Queue() def _printer(self
我开始使用 Python Behave,因为我想做一个 API 测试。 目前我偶然发现了一些甚至可能无效的东西,但问题是:我可以在功能之间共享数据吗?我可以将一些存储在数据库或文件中,但也许有一些“内
我正在尝试使用 Cucumber (Behave) 编写测试。 'given' 语句需要能够带一个可选参数,它用于验证字符串中的内容。 这两种情况的示例功能语法是: Given Verify text
我正在尝试使用 Cucumber (Behave) 编写测试。 'given' 语句需要能够带一个可选参数,它用于验证字符串中的内容。 这两种情况的示例功能语法是: Given Verify text
我有以下测试场景: 检查是否已创建具有特定名称的项目 编辑此项目 验证是否已编辑 作为拆卸过程的一部分删除此项目 下面是实现此目的的示例代码:场景: @fixture.remove_edited_
我们正在使用 Behave BDD 工具来实现 API 的自动化。是否有任何工具可以使用我们的行为案例提供代码覆盖率? 我们尝试使用覆盖模块,它不适用于 Behave。 最佳答案 您可以运行任何具有覆
如何在行为 .feature 文件中将列表或字典之类的对象作为参数传递,以便我可以在我的 python 函数步骤中使用该参数?请参阅下面我试图实现的示例: Feature: Scenario: Giv
我创建了一个自定义错误处理程序来处理失败时的屏幕截图 #error_handler.py def screenshot_handler(func): def func_wrapper(self
我有多个示例的场景大纲,如下所示: Examples: | country | type | number | | Poland | A
body { background: url(http://i.imgur.com/LMYkPk3.jpg) no-repeat center center fixed; backgr
我正在尝试实现一个简单的图像轮播,但我无法阻止图像下降到下一行。这是我的 CSS: #gallery-wrap{margin: 0 auto; overflow: hidden; width: 532
我有一个状态标签,它根据以下内容显示带有彩色边框的消息当前状态。消息本身可能会有所不同(即可以有多个消息到 ERROR),但 CLEAR 状态不同,因为它永远不应该显示任何消息。 使用示例 setSt
我目前正在使用 Behave(Python 的 BDD)并且一直在挖掘源代码以了解 @given、@when 和 @then 正在声明装饰器。 我走得最远的地方是查看 step_registry.py
我有一系列 PHPUnit 测试来验证类“A 类”。 我有另一个类,“B 类”,它扩展了 A 类。 有没有一种好的方法可以在不复制测试代码的情况下测试“B 类通过了 A 类的测试”,或者换句话说“B
如标题所示,我希望在场景大纲之前运行一些特定的配置/环境设置步骤。我知道有 Background 可以针对场景执行此操作,但 Behave 将场景大纲拆分为多个场景,从而为场景大纲中的每个输入运行后台
考虑一个 Behave 场景: When some magic number is generated Then the number should be greater than 5 所以我有一个生
有没有办法告诉 behave 在步骤实现中跳过当前步骤? 类似于: @given("bla bla bla") def step(): skip_current_step() 用例是我想检查是
我正在使用 python-behave 进行 BDD 测试,我必须从命令行传递一个 URL(例如 www.abc.com)。 $behave -u "www.abc.com" 为此,我已阅读 beha
有人可以告诉我如何使用 Python 在 Behave 中再次运行失败的测试吗? 如果失败,我想自动重新运行失败的测试用例。 最佳答案 行为库实际上有一个 RerunFormatter这可以帮助您重新
我是一名优秀的程序员,十分优秀!