From a313259a63d6f73da5ac2ca381af2d763b3995a0 Mon Sep 17 00:00:00 2001 From: Muhammad Hari Date: Sat, 31 Mar 2018 17:17:51 +0700 Subject: [PATCH] Mencari lubang terbesar dijalanan --- array/lubang_terbesar.js | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/array/lubang_terbesar.js b/array/lubang_terbesar.js index 4151ce1..e377181 100644 --- a/array/lubang_terbesar.js +++ b/array/lubang_terbesar.js @@ -1,4 +1,27 @@ +let lubangTerbesar = (array) => { + let vertikal = []; + let horizontal = []; + let countHori = 0; + + while (array[countHori] != undefined) { + horizontal[countHori] = array[countHori]; + + let countVert = 0; + while (horizontal[countHori][countVert] != undefined) { + vertikal[countVert] += horizontal[countHori][countVert]; + countVert++; + // break; + } + + countHori++; + // break; + } + + return vertikal; +}; + + console.log(lubangTerbesar(["00111", "01101", "00100", "11110"])); // 3 -console.log(lubangTerbesar(["111", "111", "111", "100"])); // 2 -console.log(lubangTerbesar(["00111", "10011", "00111", "10010","00110",'10111'])); // 6 +// console.log(lubangTerbesar(["111", "111", "111", "100"])); // 2 +// console.log(lubangTerbesar(["00111", "10011", "00111", "10010","00110",'10111'])); // 6