Skip to content

Instantly share code, notes, and snippets.

View another-guy's full-sized avatar
💻
01001000 01000101 01001100 01001100 01001111

Igor Soloydenko another-guy

💻
01001000 01000101 01001100 01001100 01001111
View GitHub Profile
@another-guy
another-guy / simple-js-stack.js
Last active August 21, 2024 22:44
LeetCode: linked-list-based stack, more performant than default JS's array-based one
function createStack() {
const empty = { next: undefined, value: undefined! };
let top = empty;
function isEmpty() { return top === empty; }
function push(v) { top = { next: top, value: v }; }
function pop() {
if (!top.next) throw new Error('Can not pop from empty');
const { value } = top;
top = top.next;
return value;
@another-guy
another-guy / simple-js-queue.js
Last active October 20, 2024 05:10
LeetCode: linked-list-based queue, more performant than default JS's array-based one
function createQueue() {
let head = undefined;
let tail = head;
function isEmpty() { return head === undefined; }
function push(value) {
const newElement = { next: undefined, value };
if (!tail) {
head = newElement;
tail = newElement;
@another-guy
another-guy / coderpad-test.ts
Last active August 22, 2024 04:42
coderpad test function
// TS
function test<T extends unknown>(actual: T, expected: T, text?: string): void {
function difference<D>(a: Set<D>, b: Set<D>) {
const arr: D[] = [];
a.forEach(d => arr.push(d));
return new Set<D>(arr.filter(x => !b.has(x)));
}
function same<S extends unknown>(o1: S, o2: S): boolean {
const t1 = typeof o1;
const t2 = typeof o2;