This file contains 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
class DungeonGenerator { | |
constructor(width, height, maxRooms, minRoomSize, maxRoomSize) { | |
this.width = width; | |
this.height = height; | |
this.maxRooms = maxRooms; | |
this.minRoomSize = minRoomSize; | |
this.maxRoomSize = maxRoomSize; | |
this.dungeon = []; | |
} |
This file contains 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
1. pr-1.js | |
On line 1, don't bind to window. This is exposing the current user details to the global namespace for no apparent reason, and is generally bad practice. (other than for a coding test demo purposes?:) | |
On line 11, I would prefer a forEach for brevity unless there's a specific need for for(), like a multidimensional array. | |
On line 12, using the Date object is fine but this should be imported from a utility that handles date conversions, with readable reusable method names such as getTimeSpan(24) ; this logic should not be in the component or we'll end up with code littered with ad hoc or repeated conversions. | |
On line 22, use <></> instead of <div></div> unless there is a specific reason for a new container other than wrapper element. |
This file contains 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
// linked list | |
// print() (traversal) is O(n) time complexity where n scales with list size | |
// remaining methods are O(1) constant time | |
class Node { | |
constructor(data) { | |
this.data = data; | |
this.next = null; | |
} | |
} |
This file contains 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
// binary search | |
// O(log n) | |
function binarySearch(array, target) { | |
let left = 0; | |
let right = array.length - 1; | |
while (left <= right) { | |
let mid = Math.floor((left + right) / 2); |
This file contains 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
/* | |
All robots are made of the same types of parts, and we have a string of all of the parts required to form a complete robot. | |
Given a list of available parts, return the collection of robot names for which we can build at least one complete robot. | |
N: Number of elements in `all_parts` | |
K: Number of robots | |
M: Number of elements in `required_parts` | |
Time Complexity: |
This file contains 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
// 2d array search | |
// O(n * m) | |
function findRectangle(image) { | |
const rows = image.length; | |
const cols = image[0].length; | |
let row = -1; | |
let col = -1; | |
let width = 0; |
This file contains 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
// breadth-first binary search | |
// O(log n) | |
/* | |
10 | |
/ \ | |
4 17 | |
/ \ / \ | |
1 9 12 18 |