Created
December 8, 2019 11:13
-
-
Save nkaurelien/8d611ac50babfb39a0f857d8a0c8fd1b to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/hinuniyixo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width"> | |
| <title>JS Bin</title> | |
| </head> | |
| <body> | |
| <script id="jsbin-javascript"> | |
| /** | |
| * @param {character[][]} grid | |
| * @return {number} | |
| */ | |
| 'use strict'; | |
| function numOffices(grid) { | |
| var result = 0; | |
| var proof = {}; | |
| (grid || []).forEach(function (table, K) { | |
| conseccutiveElCount = 0; | |
| var key = []; | |
| (table || []).forEach(function (el, idx) { | |
| if (parseInt(el)) { | |
| conseccutiveElCount++; | |
| key.push(idx); | |
| var next = parseInt(table[idx + 1]); | |
| if (!next) { | |
| proof[key.join('-')] = conseccutiveElCount; | |
| } | |
| } else { | |
| key = []; | |
| conseccutiveElCount = 0; | |
| } | |
| }); | |
| }); | |
| console.log(JSON.stringify(proof)); | |
| result = Object.keys(proof).length; | |
| return result; | |
| }; | |
| function buildKey(curr, next) {} | |
| var height = 4; | |
| var width = 5; | |
| var grid = [[1, 1, 0, 0, 0], [1, 1, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 1, 1]]; | |
| console.log(numOffices(grid)); | |
| </script> | |
| <script id="jsbin-source-javascript" type="text/javascript">/** | |
| * @param {character[][]} grid | |
| * @return {number} | |
| */ | |
| function numOffices(grid) { | |
| let result = 0; | |
| let proof = {}; | |
| (grid || []).forEach((table, K) => { | |
| conseccutiveElCount = 0; | |
| let key = []; | |
| (table || []).forEach((el, idx) => { | |
| if (parseInt(el)) { | |
| conseccutiveElCount++; | |
| key.push(idx); | |
| const next = parseInt(table[idx+1]); | |
| if(!next) { | |
| proof[key.join('-')] = conseccutiveElCount; | |
| } | |
| } else { | |
| key = []; | |
| conseccutiveElCount = 0; | |
| } | |
| }) | |
| }); | |
| console.log(JSON.stringify(proof)); | |
| result = Object.keys(proof).length | |
| return result; | |
| }; | |
| function buildKey(curr , next){ | |
| } | |
| let height = 4; | |
| let width = 5; | |
| let grid = [[1, 1, 0, 0, 0], | |
| [1, 1, 0, 0, 0], | |
| [0, 0, 1, 0, 0], | |
| [0, 0, 0, 1, 1]]; | |
| console.log(numOffices(grid));</script></body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @param {character[][]} grid | |
| * @return {number} | |
| */ | |
| 'use strict'; | |
| function numOffices(grid) { | |
| var result = 0; | |
| var proof = {}; | |
| (grid || []).forEach(function (table, K) { | |
| conseccutiveElCount = 0; | |
| var key = []; | |
| (table || []).forEach(function (el, idx) { | |
| if (parseInt(el)) { | |
| conseccutiveElCount++; | |
| key.push(idx); | |
| var next = parseInt(table[idx + 1]); | |
| if (!next) { | |
| proof[key.join('-')] = conseccutiveElCount; | |
| } | |
| } else { | |
| key = []; | |
| conseccutiveElCount = 0; | |
| } | |
| }); | |
| }); | |
| console.log(JSON.stringify(proof)); | |
| result = Object.keys(proof).length; | |
| return result; | |
| }; | |
| function buildKey(curr, next) {} | |
| var height = 4; | |
| var width = 5; | |
| var grid = [[1, 1, 0, 0, 0], [1, 1, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 1, 1]]; | |
| console.log(numOffices(grid)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment