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
// Redux Store Implementation with Middleware Support | |
function createStore(reducer, middleware) { | |
let state; | |
let listeners = []; | |
// Get the current state | |
const getState = () => state; | |
// Dispatch an action (placeholder, replaced later with middleware logic) | |
let dispatch = (action) => { |
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
class Vector { | |
constructor(x, y) { | |
this.x = x | |
this.y = y | |
} | |
add = (vector) => { | |
this.x += vector.x | |
this.y += vector.y | |
} |
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
//We can also separate this entire logic in Redux , Context API etc. Which would have made it available globally. | |
import * as React from 'react'; | |
import jwtDecode, {JwtPayload} from 'jwt-decode'; | |
interface User { | |
name: string; | |
[key: string]: string; | |
} |
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
class MinMaxPriorityQueue { | |
#heap = [] | |
#compare; | |
constructor(compare) { | |
this.#heap = []; | |
this.#compare = compare || ((a, b) => a - b) //By default, keep it MinHeap | |
} |
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
const minimizeDifference = (source, target) => { | |
const n = source.length; | |
const sourceValues = Array.from(source, char => char.charCodeAt(0) - 65); | |
const targetValues = Array.from(target, char => char.charCodeAt(0) - 65); | |
const resultValues = new Array(n); | |
let resultSum = targetValues[0]; // Start with the first target value | |
resultValues[0] = resultSum; | |
// Calculate result values based on source | |
for (let i = 1; i < n; i++) { |
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
function generateExpressions(nums, target) { | |
const results = []; | |
const evaluate = (expression) => { | |
const tokens = expression.match(/(\d+|\+|\-|\*|\/|\(|\))/g); | |
const output = []; | |
const operators = []; | |
const precedence = { '+': 1, '-': 1, '*': 2, '/': 2 }; |
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
/* | |
Date: 06-09-2024 | |
Time: 21:56 | |
Author: Pawan Kumar | |
Algorithm :Quick Select | |
Kth Largest & Kth Smallest Elements in an Array | |
*/ | |
// Function to swap elements in an array | |
function swap(arr, i, j) { |
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
console.log('Start'); | |
setTimeout(() => { | |
console.log('Inside setTimeout'); | |
}, 0); | |
Promise.resolve() | |
.then(() => { | |
console.log('Inside first promise'); | |
return new Promise((resolve) => { |
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
import { useState } from 'react'; | |
// Star component | |
const Star = ({ filled, onClick, onMouseEnter, onMouseLeave }) => ( | |
<span | |
style={{ cursor: 'pointer', fontSize: '24px', color: filled ? 'gold' : 'gray' }} | |
onClick={onClick} | |
onMouseEnter={onMouseEnter} | |
onMouseLeave={onMouseLeave} | |
> |
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
\documentclass[letterpaper,11pt]{article} | |
\usepackage{latexsym} | |
\usepackage[empty]{fullpage} | |
\usepackage{titlesec} | |
\usepackage{marvosym} | |
\usepackage[usenames,dvipsnames]{color} | |
\usepackage{enumitem} | |
\usepackage[hidelinks]{hyperref} | |
\usepackage{fancyhdr} |