我有这门课如下。x 和 y 是二维坐标
class Vector {
constructor(x, y) {
this.x = x;
this.y = y;
}
}
我有一个数组来存储坐标 x 和 y
const coordinatesStorage = [];
coordinatesStorage.push(new Vector(1, 2));
coordinatesStorage.push(new Vector(3, 4));
coordinatesStorage.push(new Vector(4, 6));
我想查找坐标存储数组中是否存在坐标(3,4)
if ( coordinatesStorage.find(Vector{x:3, y:4}) ) {
gameOver = true;
} // this code does not work
不幸的是,上面提到的是我的蹩脚方法,它无效并且返回控制台错误。我有 C++ 背景。我正在尝试将我的 Cpp 代码转换为 JS。
请帮助该代码以查找坐标存储数组中是否存在坐标(3,4)
一只甜甜圈
相关分类