Skip to content

Instantly share code, notes, and snippets.

@RahmatSaeedi
Created May 10, 2021 14:28
Show Gist options
  • Save RahmatSaeedi/b722eb87b9d6b982cc032ec311b09bca to your computer and use it in GitHub Desktop.
Save RahmatSaeedi/b722eb87b9d6b982cc032ec311b09bca to your computer and use it in GitHub Desktop.
CodeSignal - Arcade - Intro - JS - Box Blur
function boxBlur(image) {
let bluredImage = Array.from(Array(image.length-2), () => new Array(image[0].length-2));
for(let i = 1; i < image.length-1; i++) {
for(let j = 1; j < image[i].length-1; j++){
bluredImage[i-1][j-1] = Math.floor((
image[i-1][j-1] + image[i-1][j] + image[i-1][j+1] +
image[i][j-1] + image[i][j] + image[i][j+1] +
image[i+1][j-1] + image[i+1][j] + image[i+1][j+1]
)/9);
}
}
return bluredImage;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment