https://leetcode.com/problems/largest-local-values-in-a-matrix/
I used lodash
. _.chunk
makes an array to a matrix.
var largestLocal = function (grid) {
let n = grid.length;
let arr = [];
for (let ci = 1; ci < n - 1; ci++) {
for (let cj = 1; cj < n - 1; cj++) {
let s = Math.max(
grid[ci - 1][cj - 1],
grid[ci - 1][cj],
grid[ci - 1][cj + 1],
grid[ci][cj - 1],
grid[ci][cj],
grid[ci][cj + 1],
grid[ci + 1][cj - 1],
grid[ci + 1][cj],
grid[ci + 1][cj + 1]
);
arr.push(s);
}
}
return _.chunk(arr, n - 2);
};