Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @param {number[][]} M
- * @return {number[][]}
- */
- function getTop(m, i, j) {
- let sum = 0, cnt: 0;
- if(i - 1 >= 0 && j - 1 >= 0) {
- sum += m[i - 1][j - 1];
- cnt++;
- }
- if(i - 1 >= 0) {
- sum += m[i - 1][j];
- cnt++;
- }
- if(i - 1 >= 0 && j + 1 < m.length) {
- sum += m[i - 1][j + 1];
- cnt++;
- }
- return { sum, cnt };
- }
- function getMiddle(m, i, j) {
- let sum = 0, cnt: 0;
- if(j - 1 >= 0) {
- sum += m[i][j - 1];
- cnt++;
- }
- if(j + 1 < m.length) {
- sum += m[i][j + 1];
- cnt++;
- }
- return { sum, cnt };
- }
- function getBottom(m, i, j) {
- let sum = 0, cnt: 0;
- if(i + 1 < m.length && j - 1 >= 0) {
- sum += m[i + 1][j - 1];
- cnt++;
- }
- if(i + 1 < m.length) {
- sum += m[i + 1][j];
- cnt++;
- }
- if(i + 1 < m.length && j + 1 < m.length) {
- sum += m[i + 1][j + 1];
- cnt++;
- }
- return { sum, cnt };
- }
- function imageSmoother(m) {
- for(let i = 0; i < m.length; i++) {
- for(let j = 0; j < m.length; j++) {
- const top = getTop(m, i, j);
- const middle = getMiddle(m, i, j);
- const bottom = getBottom(m, i, j);
- }
- }
- return m;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement