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
<html> | |
<head> | |
<title>Star component</title> | |
<style> | |
.star-wrapper { | |
display: flex; | |
flex-direction: row-reverse; | |
justify-content: flex-end; | |
} | |
.star { |
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
<html> | |
<head> | |
<title>Accordion menu - Simple</title> | |
<style> | |
.accordion-wrapper { | |
display: flex; | |
align-items: center; | |
flex-direction: column; | |
} | |
.accordion { |
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
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] = {}; | |
} |
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
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] | |
}) |
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
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; |
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
// 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. |
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
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); | |
} |
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
// 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; |
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
const assert = require("assert"); | |
function BST(value) { | |
this.value = value; | |
this.left = null; | |
this.right = null; | |
} | |
function findKthLargestValueInBst(tree, k) { | |
const result = []; |