From 2416e1a40aa95dbe1ae2cb5ebb82809a88913779 Mon Sep 17 00:00:00 2001 From: Iwuji Anthony Date: Sat, 20 Jun 2020 15:49:37 +0100 Subject: [PATCH 1/3] Update index.js --- src/word-search/index.js | 80 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 79 insertions(+), 1 deletion(-) diff --git a/src/word-search/index.js b/src/word-search/index.js index 2e385e5..5b9f766 100644 --- a/src/word-search/index.js +++ b/src/word-search/index.js @@ -1,3 +1,81 @@ -function wordSearch(words, word) {} +function wordSearch(words, word){ + //this function searches for all the index positions(rows and columns) of the first character + //of the "word" and store them as two sets of arrays(rowIndex and colIndex) inside an object + //and return the object. These positions are the starting points to searching from. + function searchIndex(words,word){ + let rowIndex=[]; + let colIndex=[]; + + for(let row=0; row=0 && words[row-1]!==undefined && words[row-1][col]==word[indexPositionsOfWord]){ + words[row-1][col]=0 + if(checkNextChar(words,word,(row-1),col,indexPositionsOfWord+1)){ + return true; + } + + } + if(col-1>=0 && words[row][col-1]!=undefined && words[row][col-1]==word[indexPositionsOfWord]){ + words[row][col-1]=0 + if(checkNextChar(words,word,(row),col-1,indexPositionsOfWord+1)){ + return true; + } + + } + if(col+1<=words[0].length && words[row][col+1]!=undefined && words[row][col+1]==word[indexPositionsOfWord]){ + words[row][col+1]=0 + if(checkNextChar(words,word,(row),col+1,indexPositionsOfWord+1)){ + return true; + } + } + return 0; + } + return manager(searchIndex(words,word)); +} module.exports = wordSearch; From 20d1a73dc0af2cc1231e55bcab3913e60ecaf0d2 Mon Sep 17 00:00:00 2001 From: Iwuji Anthony Date: Sat, 20 Jun 2020 16:12:42 +0100 Subject: [PATCH 2/3] Update index.js --- src/count-islands/index.js | 47 +++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/src/count-islands/index.js b/src/count-islands/index.js index ec88f6b..a7d6fd7 100644 --- a/src/count-islands/index.js +++ b/src/count-islands/index.js @@ -1,3 +1,48 @@ -function countIslands(grid) {} +function countIslands(grid) { + //This function directs every activities that goes on here. it calls the checkDreyLand function, + //which searches for inland, gives it the axis of the point to start seach from and collects + //feedback from it. + function manager(matrix){ + let inlandRecorder=0; + for(let row=0; row=0 && matrix[axisX-1]!==undefined && matrix[axisX-1][axisY]==1){ + matrix[axisX-1][axisY]=0; + checkDryLand(matrix,axisX-1,axisY); + } + //checking adjacent left + if(axisY-1>=0 && matrix[axisX][axisY-1]!=undefined && matrix[axisX][axisY-1]==1){ + matrix[axisX][axisY-1]=0; + checkDryLand(matrix,axisX,axisY-1); + } + //checking adjacent right + if(axisY+1<=matrix[0].length && matrix[axisX][axisY+1]!=undefined && matrix[axisX][axisY+1]==1){ + matrix[axisX][axisY+1]=0; + checkDryLand(matrix,axisX,axisY+1); + } + return "Thank you"; + } + //the manager is done and about to return result to the company owner(i.e countIsland). Always remember + //that the compant owner(countIsland) reports it the creator. Which is YOU... + return manager(grid); +} +} module.exports = countIslands; From b9decf45f35d128de966d042736772f0c0bccf34 Mon Sep 17 00:00:00 2001 From: Iwuji Anthony Date: Sat, 20 Jun 2020 16:22:50 +0100 Subject: [PATCH 3/3] Update index.js --- src/count-islands/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/count-islands/index.js b/src/count-islands/index.js index a7d6fd7..1b7c5ce 100644 --- a/src/count-islands/index.js +++ b/src/count-islands/index.js @@ -43,6 +43,6 @@ function countIslands(grid) { //that the compant owner(countIsland) reports it the creator. Which is YOU... return manager(grid); } -} + module.exports = countIslands;