Skip to content

Commit

Permalink
Merge pull request #2 from renderforest/task-1-sulution
Browse files Browse the repository at this point in the history
Solution for Box blur algorithm task
  • Loading branch information
karengyuzalyan authored Jun 1, 2022
2 parents 6c18c8e + 2d59c4b commit bfb34d1
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions box_blur_algorithm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const IMAGE = [
[7, 4, 0, 1],
[5, 6, 2, 2],
[6, 10, 7, 8],
[1, 4, 2, 0]
]

function solution(image) {
const rowPossibleSubs = image[0].length - 2
const colPossibleSubs = image.length - 2
const result = []
for(let i = 0; i < colPossibleSubs; i++) {
result[i] = []
for(let j = 0; j < rowPossibleSubs; j++ ) {
let sum = 0
for(let k = i; k < i + 3; k++) {
for(let g = j; g < j + 3; g++) {
sum += image[k][g]
}
}
result[i][j] = Math.floor(sum/9)
}
}
return result
}

console.log(solution(IMAGE))

0 comments on commit bfb34d1

Please sign in to comment.