Skip to content

Instantly share code, notes, and snippets.

View cagataycali's full-sized avatar

./c² cagataycali

View GitHub Profile
@cagataycali
cagataycali / index.html
Created November 24, 2021 04:03
Star component - simple
<html>
<head>
<title>Star component</title>
<style>
.star-wrapper {
display: flex;
flex-direction: row-reverse;
justify-content: flex-end;
}
.star {
@cagataycali
cagataycali / index.html
Last active November 24, 2021 01:05
[HTML] Accordion menu - simple
<html>
<head>
<title>Accordion menu - Simple</title>
<style>
.accordion-wrapper {
display: flex;
align-items: center;
flex-direction: column;
}
.accordion {
@cagataycali
cagataycali / button-generator.html
Last active November 25, 2021 02:48
HTML Button generator
<html>
<head>
<title>Button Generator</title>
<style>
#container button {
padding: 1rem;
margin: 1rem;
border-color: transparent;
border-radius: 5px;
color: white;
@cagataycali
cagataycali / bad-words.js
Last active November 24, 2021 09:57
[JavaScript] Bad word finder
const assert = require("assert");
function generateTrie(array) {
const trie = { "": {} };
for (const word of array) {
let currentNode = trie[""];
Array.from(word).forEach((char) => {
if (!currentNode[char]) {
currentNode[char] = {};
}
@cagataycali
cagataycali / hashmap-of-hashmaps.js
Last active November 22, 2021 15:38
[JavaScript] Hashmap of hashmaps
function generate(...input) {
const tree = {'': {}};
for (const text of input) {
let currentNode = tree[''];
Array.from(text).forEach(char => {
if (!currentNode[char]) {
currentNode[char] = {};
}
currentNode = currentNode[char]
})
@cagataycali
cagataycali / debounce.js
Created November 22, 2021 12:23
[JavaScript] Debounce
function debounce(func, wait, immediate) {
let timeout = null;
return function () {
let context = this;
let args = arguments;
const later = function () {
timeout = null;
if (!immediate) func.apply(context, args);
}
const callNow = immediate && !timeout;
@cagataycali
cagataycali / bind.js
Created November 22, 2021 12:21
[JavaScript] Naive bind
// Bind returns function closure for later usage,
Function.prototype.myBind = function (context) {
const fn = this;
return function () {
fn.apply(context, arguments);
}
}
// Apply, bind invokes the function immediately.
@cagataycali
cagataycali / depths.js
Created November 17, 2021 06:46
[BinaryTree] Node depths
const assert = require("assert");
// O(n) time | O(h) space - h is height.
function nodeDepths(root, depth = 0) {
if (root === null) {
return 0;
}
return depth + nodeDepths(root.left, depth + 1) + nodeDepths(root.right, depth + 1);
}
@cagataycali
cagataycali / invert.js
Created November 16, 2021 20:00
[JavaScript] Invert binary tree
// O(n) time & space
function invertBinaryTree(tree) {
if (tree === null) return;
swapLeftAndRight(tree);
invertBinaryTree(tree.left);
invertBinaryTree(tree.right);
}
function swapLeftAndRight(tree) {
const left = tree.left;
@cagataycali
cagataycali / find-kth-largest.js
Last active November 16, 2021 19:34
[JavaScript] Binary search tree find kth largest value
const assert = require("assert");
function BST(value) {
this.value = value;
this.left = null;
this.right = null;
}
function findKthLargestValueInBst(tree, k) {
const result = [];