这更像是一个逻辑问题。 我不知道我的函数出了什么问题
// This function is meant to check if 3 pixels
// are colored and therefore if the canvas is full
function checkIfFull() {
let emptyPixel = [0, 0, 0, 0];
let pixel1 = get(1, 1);
//let pixel2 = get(599,599);
//let pixel3 = get(400, 50);
console.log(pixel1);
if (pixel1 === emptyPixel) {
console.log(true);
} else {
console.log(false);
}
}
我正在运行 P5.js 库。 get() 给了我一个数组 [a, b, c, d] 我正在尝试测试这两者之间的相等或差异(emptyPixel/Pixel1)
这些是我尝试过的事情:测试数组中的每个位置。
谢谢!
最佳答案
如果空像素是一个数组 [0,0,0,0],你可以用这样的东西来测试它
function checkIfEmpty(pixel) {
return pixel.every(x => x === 0)
}
关于javascript - 两个数组相等测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55151199/