MCPcopy
hub / github.com/TheAlgorithms/JavaScript / largestProductInAGrid

Function largestProductInAGrid

Project-Euler/Problem011.js:32–51  ·  view source on GitHub ↗
(arr)

Source from the content-addressed store, hash-verified

30 */
31
32export function largestProductInAGrid(arr) {
33 let max = 0
34 const k = 4
35
36 const dx = [1, 0, 1, -1]
37 const dy = [0, 1, 1, 1]
38
39 for (let y = 0; y < arr.length; y++) {
40 for (let x = 0; x < arr[y].length; x++) {
41 for (let d = 0; d < 4; d++) {
42 let p = 1
43 for (let i = 0; i < k; i++) {
44 p *= get(arr, y + i * dy[d], x + i * dx[d])
45 }
46 max = Math.max(p, max)
47 }
48 }
49 }
50 return max
51}
52
53function get(arr, y, x) {
54 if (y >= 0 && y < arr.length && x >= 0 && x < arr[y].length) {

Callers 1

Problem011.test.jsFile · 0.90

Calls 1

getFunction · 0.85

Tested by

no test coverage detected