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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Masonry Grid Layout</title> | |
<style> | |
body { | |
font-family: Arial, sans-serif; |
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
# OOPS (Inheritance, Polymorphism, Encapsulation, Abstraction) | |
""" | |
Access Modifiers: | |
public : We can anything from anywhere | |
protected : Only inside the class & subclass (_) | |
private : Only inside the class (__) | |
""" | |
# Encapsulation |
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
30 days | |
1. Two Sum | |
54.9% | |
Easy | |
146. LRU Cache | |
44.3% | |
Med. | |
200. Number of Islands |
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
import * as React from 'react' | |
export default function App() { | |
const [grid, setGrid] = React.useState(Array.from({ length: 3 }, () => Array.from({ length: 3 }, () => false | |
))) | |
const cellsRef = React.useRef([]) | |
const timerRef = React.useRef([]) | |
const handleCellClick = (i, j, check) => { | |
if (grid[i][j] && check) return |
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 MiniQuery { | |
constructor(selector) { | |
this.elements = document.querySelectorAll(selector); | |
} | |
css(property, value) { | |
this.elements.forEach(el => el.style[property] = value); | |
return this; // Enable chaining | |
} |
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 Board { | |
constructor() { | |
this.grid = [ | |
["", "", ""], | |
["", "", ""], | |
["", "", ""] | |
]; | |
} | |
printBoard() { |
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 Board { | |
constructor(size) { | |
this.size = size; // e.g., 20x20 grid | |
this.food = this.generateFood(); | |
} | |
generateFood() { | |
return { | |
x: Math.floor(Math.random() * this.size), | |
y: Math.floor(Math.random() * this.size) |
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 Dice { | |
roll() { | |
return Math.floor(Math.random() * 6) + 1; | |
} | |
} | |
class Token { | |
constructor(color, id) { | |
this.color = color; | |
this.id = id; |
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 Piece { | |
constructor(color, name) { | |
this.color = color; // "White" or "Black" | |
this.name = name; | |
} | |
isValidMove(start, end, board) { | |
return false; // Each piece will override this method | |
} | |
} |
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 Dice { | |
roll() { | |
return Math.floor(Math.random() * 6) + 1; | |
} | |
} | |
class Board { | |
constructor(size, snakes, ladders) { | |
this.size = size; | |
this.snakes = new Map(snakes); // {start: end} |
NewerOlder