Im trying to maken a function to use the AND-Logicgate but it only respons an array.
I tryed useing toString() and join() but they dont work. Can anybody help me.
Here is the Code:
Array.prototype.AND = function() {
var temp = true;
for (let i = 0; i < this.length; i++) {
if (this[i] == false) {
temp = false;
}
}
while (this.length > 0) {
this.pop();
}
this[0] = temp;
}
const test = [true, true, true, false];
test.AND();
console.log(test);
>Solution :
So if the array contains a false, the prototyped function .AND should return false.
Use some to determine if the array contains a false.
const test = [true, true, true, false];
const test2 = [true, true, true, true];
Array.prototype.AND = function() {
return !this.some(item => item == false)
}
console.log(test.AND()) // false
console.log(test2.AND()) // true