I try this code to check val in array2 is square in val array1, my code it works but i get error 'TypeError: Cannot read property 'forEach' of null'
let comp = (array1, array2) => {
var index;
if (array1.length === null && array2.length === null) return false;
array2.forEach( (val) => {
if (array1.includes(Math.sqrt(val))) {
index = array1.indexOf(Math.sqrt(val));
array1.splice(index, 1);
}
});
return array1.length == 0 ? true : false;
}
Try adding this line at the top of the function:
let comp = (array1, array2) => {
var index;
if (array1 == null && array2 == null) return false;
// Rest of the function
}
I guess instead of checking array2.length === null you should try array2.length === 0