我试图让它检测二维数组中的元素是否都相等,但无论它们是否相等,我都对它们保持“真”。
const isEqual = (currentValue) => currentValue = 5
const r = 0
array = [
[1,2,3,4],
[5,5,5,5],
[6,7,8,9],
[10,11,12,13]
];
for (i = 0; i < array.length; i++) {
result = (array[i].every(isEqual));
if(result == true) {
r == i + 1
}
console.info("Row " + [i] + " has all equal values.")
}
并期待它说第 2 行具有所有相等的值。
但是我得到了这个
Row 0 has all equal values.
Row 1 has all equal values.
Row 2 has all equal values.
Row 3 has all equal values.
const isEqual = (currentValue) => currentValue === 5;
let r = 0;
array = [
[1, 2, 3, 4],
[5, 5, 5, 5],
[6, 7, 8, 9],
[10, 11, 12, 13],
];
for (let i = 0; i < array.length; i++) {
result = array[i].every(isEqual);
if (result === true) {
r = i + 1;
console.info("Row " + [i] + " has all equal values.");
}
}