Today I wrote code for some programming contest. When I run it I was surprised because of error. Cannot read property 'forEach' of undefined in a place where looks like "error free space".
sum = 0
[-1,0,1].forEach(deltar =>{...});
When I add semicolon after sum
variable value assignment code start to works.
sum = 0;
[-1,0,1].forEach(deltar =>{...});
It's very curious about JS behavior what do interpreter mismatch here? how do JS mess with integer and array after it?
Here it is a full code of the function to make the complete picture of variables declaration.
function boxBlur(img) {
let [h,w] = [img.length-1,img[0].length-1];
let [answer,sum,tmp] = [[],0,[]]
for(let row = 1; row < h; row += 1){
tmp = []
for(let clmn = 1; clmn < w; clmn += 1){
sum = 0;
[-1,0,1].forEach(deltar =>{
[-1,0,1].forEach(deltac =>{
sum += img[row+deltar][clmn+deltac]
});
});
tmp.push(parseInt(sum/9));
}
answer.push(tmp);
}
return answer;
}
WHAT I WANT TO DO I want to shorten my code. This Drum Play App plays sound by pressing certain keys or clicking with your mouse. It works, but the code for click events is too long because I ...
WHAT I WANT TO DO I want to shorten my code. This Drum Play App plays sound by pressing certain keys or clicking with your mouse. It works, but the code for click events is too long because I ...
I want to make sure that I can't push a duplicated value into an array in a React state. The duplicated value is still going in the array though. I have tried using .includes but it is not working. ...
I want to make sure that I can't push a duplicated value into an array in a React state. The duplicated value is still going in the array though. I have tried using .includes but it is not working. ...
Problem Let's make a basic list and sort it to make sure that 2 is ALWAYS first in the list. Simple enough, right? [1, 2, 3].sort((a, b) => { if (a === 2) return -1; return 0; }); Chrome ...
Problem Let's make a basic list and sort it to make sure that 2 is ALWAYS first in the list. Simple enough, right? [1, 2, 3].sort((a, b) => { if (a === 2) return -1; return 0; }); Chrome ...
I need to handle multiple event which will generate same HTML dynamically. I have added addEventListener for all elements. Also getting different event value. Now i just need to set this result to ...
I need to handle multiple event which will generate same HTML dynamically. I have added addEventListener for all elements. Also getting different event value. Now i just need to set this result to ...