Skip to content

Instantly share code, notes, and snippets.

@IAmAnubhavSaini
IAmAnubhavSaini / fun.js
Created July 17, 2024 20:44
have fun with javascript
[10, 2, NaN, " a string", 1.232, true, false, Infinity, 1, -0, 0, -Infinity, {}].sort();
[10, 2, NaN, " a string", 1.232, true, false, Infinity, 1, -0, 0, -Infinity, {}].sort((a, b) => a - b);
[10, 2, NaN, " a string", 1.232, true, false, Infinity, 1, -0, 0, -Infinity, {}].sort((a, b) => b - a);
@IAmAnubhavSaini
IAmAnubhavSaini / nuc-draft4.md
Created July 12, 2024 18:45
Draft 4 for a new c

Draft 4 of a-new-c


/*! type Rectangle
  * defines a type named Rectangle; this would be like a class in many other languages
  * defines a complete implementation as per the spec/ideas today
  * */
type Rectangle {
@IAmAnubhavSaini
IAmAnubhavSaini / analysis.draft.md
Created July 7, 2024 08:55 — forked from MattPD/analysis.draft.md
Program Analysis Resources (WIP draft)
@IAmAnubhavSaini
IAmAnubhavSaini / course-schedule.js
Created March 21, 2024 05:48
207. Course schedule
"use strict";
class Graph {
#InitialCourses;
constructor(edges) {
this.E = new Map();
this.V = new Set();
this.I = new Map();
this.#InitialCourses = [];
if (edges.length === 0) {
return;
@IAmAnubhavSaini
IAmAnubhavSaini / bipartite_matching.js
Created March 21, 2024 01:48
interviews be like...
class Graph {
constructor(edgesArray) {
this.V = new Set();
this.E = {};
if(edgesArray.length === 0) {
return this;
}
edgesArray.forEach(edge => {
@IAmAnubhavSaini
IAmAnubhavSaini / multiply-strings.js
Created March 18, 2024 20:24
Big strings multiplication
/**
* @param {string} num1
* @param {string} num2
* @return {string}
*/
var multiply = function(num1, num2) {
if(num1 === "0" || num2 === "0") {
return "0";
}
const numbers = Array.from({length: num2.length}, _ => "0");
@IAmAnubhavSaini
IAmAnubhavSaini / future.js
Created March 18, 2024 16:39
generatePairs and Future
class Future {
#value = null;
#error = null;
#successCallbacks = [];
#failureCallback = () => {}
#finalCallback = () => {}
constructor(fn) {
const onSuccess = (value) => {
this.#value = value;
@IAmAnubhavSaini
IAmAnubhavSaini / 36.valid-sudoku.js
Created August 31, 2023 06:18
36. valid sudoku
/**
* @param {character[][]} board
* @return {boolean}
*/
var isValidSudoku = function(board) {
toString(board);
const len = board.length;
let valid = true;
for(let i = 0; i < len && valid; i++) {
valid = valid && isValidRow(board, i) && isValidColumn(board, i);
@IAmAnubhavSaini
IAmAnubhavSaini / bash_strict_mode.md
Last active January 2, 2023 13:43 — forked from mohanpedala/bash_strict_mode.md
bash_strict_mode

Quick

#!/usr/bin/env bash

set -euxo pipefail
IFS=$'\n\t'

set -euxo pipefail