{"version":3,"sources":["Grid.jsx","Calculate.jsx","App.js","serviceWorker.js","index.js"],"names":["Row","array","rowKey","map","square","idx","key","className","Rows","grid","row","Grid","props","Calculate","visited","createGrid","useState","numberOfIslands","setNumberOfIslands","useEffect","totalVisited","x","length","y","dfs","onClick","islands","App","setLength","setGrid","setVisited","value","size","temp","vTemp","i","vRow","ii","push","Math","round","random","href","target","style","margin","onChange","e","Fragment","Boolean","window","location","hostname","match","ReactDOM","render","document","getElementById","navigator","serviceWorker","ready","then","registration","unregister","catch","error","console","message"],"mappings":"kPAUMA,G,MAAM,SAAC,GAAuB,IAArBC,EAAoB,EAApBA,MAAOC,EAAa,EAAbA,OAWpB,OAVYD,EAAME,KAAI,SAACC,EAAQC,GAC7B,OACE,yBACEC,IAAG,UAAKJ,EAAL,YAAeG,GAClBE,UAAS,iBAAYH,EAAS,OAAS,QAEtCA,QAaHI,EAAO,SAAC,GASZ,OATyB,EAAXC,KACIN,KAAI,SAACO,EAAKL,GAC1B,IAAMC,EAAMD,EACZ,OACE,yBAAKC,IAAKA,GACR,kBAAC,EAAD,CAAKL,MAAOS,EAAKR,OAAQI,SAqBlBK,EATF,SAAAC,GAAU,IACbH,EAASG,EAATH,KACR,OACE,yBAAKF,UAAU,cACb,kBAAC,EAAD,CAAME,KAAMA,MCqCHI,EA9EG,SAAAD,GAAU,IAClBH,EAA8BG,EAA9BH,KAAMK,EAAwBF,EAAxBE,QAASC,EAAeH,EAAfG,WADE,EAGqBC,mBAAS,GAH9B,mBAGlBC,EAHkB,KAGDC,EAHC,KASzBC,qBAAU,WAER,IADA,IAAIC,EAAe,EACVC,EAAI,EAAGA,EAAIP,EAAQQ,OAAQD,GAAK,EACvC,IAAK,IAAIE,EAAI,EAAGA,EAAIT,EAAQO,GAAGC,OAAQC,GAAK,EAC1CH,GAAgBN,EAAQO,GAAGE,GAG/BL,EAAmBE,KAClB,CAACN,IASJ,IAAMU,EAAM,SAANA,EAAOH,EAAGE,GACd,OACEF,EAAI,GACJA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D,KAAK,kDAAkDC,OAAO,QAAjE,WAEF,8CACA,yBAAKC,MAAO,CAAEC,OAAQ,QACpB,0BAAMD,MAAO,CAAEC,OAAQ,QAAvB,sBACA,4BACEC,SAAU,SAAAC,GAAM,IAEFhB,EACRgB,EADFJ,OAAUZ,MAEZH,EAAUG,GACVhB,EAAWgB,KAGb,4BAAQA,MAAO,GAAf,KACA,4BAAQA,MAAO,IAAf,MACA,4BAAQA,MAAO,IAAf,MACA,4BAAQA,MAAO,IAAf,QAGHtB,GACC,kBAAC,IAAMuC,SAAP,KACE,kBAAC,EAAD,CAAMvC,KAAMA,IACZ,kBAAC,EAAD,CACEA,KAAMA,EACNK,QAASA,EACTC,WAAY,kBAAMA,SAItBN,GAAQ,4BAAQgB,QAAS,kBAAMV,MAAvB,cChEIkC,QACW,cAA7BC,OAAOC,SAASC,UAEe,UAA7BF,OAAOC,SAASC,UAEhBF,OAAOC,SAASC,SAASC,MACvB,2DCZNC,IAASC,OAAO,kBAAC,EAAD,MAASC,SAASC,eAAe,SD6H3C,kBAAmBC,WACrBA,UAAUC,cAAcC,MACrBC,MAAK,SAAAC,GACJA,EAAaC,gBAEdC,OAAM,SAAAC,GACLC,QAAQD,MAAMA,EAAME,c","file":"static/js/main.efc9cdd2.chunk.js","sourcesContent":["/** @module Grid */\r\n\r\nimport React from \"react\";\r\n\r\n/**\r\n * @function Row\r\n * @description returns Row\r\n * @param {Object} props \r\n * @returns {React.Component}\r\n */\r\nconst Row = ({ array, rowKey }) => {\r\n const row = array.map((square, idx) => {\r\n return (\r\n \r\n {square}\r\n \r\n );\r\n });\r\n return row;\r\n};\r\n\r\n/**\r\n * @function Rows\r\n * @description returns Rows (Grid)\r\n * @param {Object} props \r\n * @returns {React.Component}\r\n */\r\nconst Rows = ({ grid }) => {\r\n const rows = grid.map((row, idx) => {\r\n const key = idx;\r\n return (\r\n
\r\n \r\n
\r\n );\r\n });\r\n return rows;\r\n};\r\n\r\n/**\r\n * @function Grid\r\n * @description Presentational Component that converts grid array to visual grid\r\n * @param {Object} props \r\n */\r\nconst Grid = props => {\r\n const { grid } = props;\r\n return (\r\n
\r\n \r\n
\r\n );\r\n};\r\n\r\nexport default Grid;\r\n","/** @module Calculate */\r\n\r\nimport React, { useState, useEffect } from \"react\";\r\n\r\n/**\r\n * @function Calculate\r\n * @description Component with logic for determining number of islands\r\n * @param {Object} props \r\n * @returns {React.Component}\r\n */\r\nconst Calculate = props => {\r\n const { grid, visited, createGrid } = props;\r\n\r\n const [numberOfIslands, setNumberOfIslands] = useState(0);\r\n\r\n /**\r\n * @function useEffect\r\n * @description useEffect to generate empty \"visited\" array\r\n */\r\n useEffect(() => {\r\n let totalVisited = 0;\r\n for (let x = 0; x < visited.length; x += 1) {\r\n for (let y = 0; y < visited[x].length; y += 1) {\r\n totalVisited += visited[x][y];\r\n }\r\n }\r\n setNumberOfIslands(totalVisited);\r\n }, [visited]);\r\n\r\n /**\r\n * @function dfs\r\n * @description deep field search recursive helper function\r\n * @param {Number} x coordinate\r\n * @param {Number} y coordinate\r\n * @returns {Number} 1 (new island) or 0 (water or visited land)\r\n */\r\n const dfs = (x, y) => {\r\n if (\r\n x < 0 ||\r\n x >= grid.length ||\r\n y < 0 ||\r\n y >= grid[x].length ||\r\n grid[x][y] === 0 ||\r\n visited[x][y] === 1\r\n ) {\r\n return 0;\r\n }\r\n visited[x][y] = 1;\r\n dfs(x + 1, y);\r\n dfs(x - 1, y);\r\n dfs(x, y + 1);\r\n dfs(x, y - 1);\r\n return 1;\r\n };\r\n\r\n /**\r\n * @function calculateIslands\r\n * @description iterates through grid; upon encountering land, it calls dfs() to\r\n * isolate extent of discovered island (so it is only counted once), then increments island count\r\n */\r\n const calculateIslands = () => {\r\n if (!grid || !grid.length) {\r\n setNumberOfIslands(0);\r\n }\r\n let islands = 0;\r\n for (let x = 0; x < grid.length; x += 1) {\r\n for (let y = 0; y < grid[x].length; y += 1) {\r\n if (grid[x][y] === 1) {\r\n islands += dfs(x, y);\r\n }\r\n }\r\n }\r\n\r\n setNumberOfIslands(islands);\r\n };\r\n\r\n return (\r\n
\r\n {!numberOfIslands ? (\r\n \r\n ) : (\r\n \r\n )}\r\n {numberOfIslands > 0 &&
Number of Islands: {numberOfIslands}
}\r\n
\r\n );\r\n};\r\n\r\nexport default Calculate;\r\n","/** @module App */\n\nimport React, { useState } from \"react\";\n\nimport \"./App.css\";\n\nimport Grid from \"./Grid\";\nimport Calculate from \"./Calculate\";\n\n/**\n * @function App\n * @description Functional Component for Island Problem app\n * @returns {React.Component}\n */\nfunction App() {\n const [length, setLength] = useState(5);\n const [grid, setGrid] = useState(null);\n const [visited, setVisited] = useState(null);\n\n /**\n * @function createGrid\n * @description generates x by x grid, each square is either land (\"1\") or water (\"0\") 50/50\n * @param {Number} value - Optional; size of grid being created\n */\n const createGrid = value => {\n const size = value ? value : length;\n const temp = [];\n const vTemp = [];\n for (let i = 0; i < size; i += 1) {\n const row = [];\n const vRow = [];\n for (let ii = 0; ii < size; ii += 1) {\n row.push(Math.round(Math.random()));\n vRow.push(0);\n }\n temp.push(row);\n vTemp.push(vRow);\n }\n setGrid(temp);\n setVisited(vTemp);\n };\n\n return (\n
\n
\n rbr.com\n GitHub\n
\n

Island Problem

\n
\n Number of Squares:\n {\n const {\n target: { value }\n } = e;\n setLength(value);\n createGrid(value);\n }}\n >\n \n \n \n \n \n
\n {grid && (\n \n \n createGrid()}\n />\n \n )}\n {!grid && }\n
\n );\n}\n\nexport default App;\n","// This optional code is used to register a service worker.\n// register() is not called by default.\n\n// This lets the app load faster on subsequent visits in production, and gives\n// it offline capabilities. However, it also means that developers (and users)\n// will only see deployed updates on subsequent visits to a page, after all the\n// existing tabs open on the page have been closed, since previously cached\n// resources are updated in the background.\n\n// To learn more about the benefits of this model and instructions on how to\n// opt-in, read https://bit.ly/CRA-PWA\n\nconst isLocalhost = Boolean(\n window.location.hostname === 'localhost' ||\n // [::1] is the IPv6 localhost address.\n window.location.hostname === '[::1]' ||\n // 127.0.0.0/8 are considered localhost for IPv4.\n window.location.hostname.match(\n /^127(?:\\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/\n )\n);\n\nexport function register(config) {\n if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {\n // The URL constructor is available in all browsers that support SW.\n const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);\n if (publicUrl.origin !== window.location.origin) {\n // Our service worker won't work if PUBLIC_URL is on a different origin\n // from what our page is served on. This might happen if a CDN is used to\n // serve assets; see https://github.com/facebook/create-react-app/issues/2374\n return;\n }\n\n window.addEventListener('load', () => {\n const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;\n\n if (isLocalhost) {\n // This is running on localhost. Let's check if a service worker still exists or not.\n checkValidServiceWorker(swUrl, config);\n\n // Add some additional logging to localhost, pointing developers to the\n // service worker/PWA documentation.\n navigator.serviceWorker.ready.then(() => {\n console.log(\n 'This web app is being served cache-first by a service ' +\n 'worker. To learn more, visit https://bit.ly/CRA-PWA'\n );\n });\n } else {\n // Is not localhost. Just register service worker\n registerValidSW(swUrl, config);\n }\n });\n }\n}\n\nfunction registerValidSW(swUrl, config) {\n navigator.serviceWorker\n .register(swUrl)\n .then(registration => {\n registration.onupdatefound = () => {\n const installingWorker = registration.installing;\n if (installingWorker == null) {\n return;\n }\n installingWorker.onstatechange = () => {\n if (installingWorker.state === 'installed') {\n if (navigator.serviceWorker.controller) {\n // At this point, the updated precached content has been fetched,\n // but the previous service worker will still serve the older\n // content until all client tabs are closed.\n console.log(\n 'New content is available and will be used when all ' +\n 'tabs for this page are closed. See https://bit.ly/CRA-PWA.'\n );\n\n // Execute callback\n if (config && config.onUpdate) {\n config.onUpdate(registration);\n }\n } else {\n // At this point, everything has been precached.\n // It's the perfect time to display a\n // \"Content is cached for offline use.\" message.\n console.log('Content is cached for offline use.');\n\n // Execute callback\n if (config && config.onSuccess) {\n config.onSuccess(registration);\n }\n }\n }\n };\n };\n })\n .catch(error => {\n console.error('Error during service worker registration:', error);\n });\n}\n\nfunction checkValidServiceWorker(swUrl, config) {\n // Check if the service worker can be found. If it can't reload the page.\n fetch(swUrl, {\n headers: { 'Service-Worker': 'script' }\n })\n .then(response => {\n // Ensure service worker exists, and that we really are getting a JS file.\n const contentType = response.headers.get('content-type');\n if (\n response.status === 404 ||\n (contentType != null && contentType.indexOf('javascript') === -1)\n ) {\n // No service worker found. Probably a different app. Reload the page.\n navigator.serviceWorker.ready.then(registration => {\n registration.unregister().then(() => {\n window.location.reload();\n });\n });\n } else {\n // Service worker found. Proceed as normal.\n registerValidSW(swUrl, config);\n }\n })\n .catch(() => {\n console.log(\n 'No internet connection found. App is running in offline mode.'\n );\n });\n}\n\nexport function unregister() {\n if ('serviceWorker' in navigator) {\n navigator.serviceWorker.ready\n .then(registration => {\n registration.unregister();\n })\n .catch(error => {\n console.error(error.message);\n });\n }\n}\n","import React from 'react';\nimport ReactDOM from 'react-dom';\nimport './index.css';\nimport App from './App';\nimport * as serviceWorker from './serviceWorker';\n\nReactDOM.render(, document.getElementById('root'));\n\n// If you want your app to work offline and load faster, you can change\n// unregister() to register() below. Note this comes with some pitfalls.\n// Learn more about service workers: https://bit.ly/CRA-PWA\nserviceWorker.unregister();\n"],"sourceRoot":""}