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 CORRECT = 'correct'; | |
const OUT_OF_PLACE = 'out of place'; | |
const WRONG = 'wrong'; | |
/** | |
* Determines which letters in a given guess are correct, which ones are out of place, and which ones are invalid | |
* @param {string} solution the target word the player is trying to guess | |
* @param {string} guess five-letter guess (presumes the guess has already been through other formatting validations like length and valid characters) | |
* @returns {{letter: string, state: CORRECT | OUT_OF_PLACE | WRONG}[]} | |
*/ |
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
/** | |
* Gets all possible capitalizations of the given string | |
* @param {string} str string to get capitalization permutations of | |
* @returns {string[]} list of all possible capitalization of the given string | |
*/ | |
function capPermutations(str) { | |
let characters = str.split(''); | |
let permutations = ['']; | |
for (let character of characters) { | |
// Character isn't a capitalizable letter, so tack it on to all visited permutations so far |
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
/** | |
* @typedef {object} Point | |
* @property {string} name | |
* @property {string[]} connections | |
*/ | |
/** @type {Point[]} */ | |
const listOfPoints = [ | |
{ name: 'A', connections: ['B', 'C'] }, | |
{ name: 'B', connections: ['A', 'E'] }, |
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
/** | |
* @type {Object<String, String[]>} | |
*/ | |
const keypad = { | |
'2': ['a', 'b', 'c'], | |
'3': ['d', 'e', 'f'], | |
'4': ['g', 'h', 'i'], | |
'5': ['j', 'k', 'l'], | |
'6': ['m', 'n', 'o'], | |
'7': ['p', 'q', 'r', 's'], |
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
/** | |
* Take an array of phrases and return a list of anagram groups | |
* @param {string[]} phrases list of strings which may or may not be anagrams of other strings in the same list | |
* @returns {string[][]} a list of arrays of strings, where every string in an inner array is an anagram of the others | |
*/ | |
function groupAnagrams(phrases) { | |
/** @type {Object<string, string[]>} */ | |
const anagramGroups = {}; | |
// Create a map of anagram groups |
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 el() { | |
mkdir "$1" | |
cd "$1" | |
git init | |
mkdir -p src/_data/ | |
mkdir src/_includes/ | |
# Populate .gitignore | |
echo "# Node" >> .gitignore |
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
/** | |
* Determines whether a given number is "odious" (its binary expansion has an odd number of ones) | |
* @param {number} num non-negative integer to test odiousness of | |
* @returns {boolean} whether `num` is odious | |
*/ | |
function isOdious(num) { | |
let numberOf1Bits = 0; | |
// Binary expansions represent numbers as sums of powers of 2 | |
// So we need to find how many powers of 2 can be subtracted from `num` |
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
:root { | |
--twitch-gray: rgb(173, 173, 184); | |
--twitch-light: rgb(239, 239, 241); | |
--twitch-dark-background: rgb(24, 24, 27); | |
--twitch-purple: rgb(180, 84, 255); | |
} | |
body { | |
background-color: var(--twitch-light); | |
} |
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
/** | |
* Simplified `splice` implementation that doesn't handle all the different use cases for `start`. | |
* | |
* Deleting items in-place without using `splice` is hard. Here's the plan: | |
* 1. Create an array (`deletedItems`) of items which the user WANTS to remove from the array. | |
* 2. Create an array (`reinsertedItems`) of all items that come AFTER the deleted items. | |
* 3. Truncate the whole array to everything UP TO `start`. | |
* 4. Insert any new items provided by the user. | |
* 5. Reinsert everything in `reinsertedItems`. | |
* 6. Return `deletedItems`. |
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 FIGURE_WITH_LAZY = /<img\s+.*lazy=.*>/g; | |
const addLazy = (token) => { | |
if (token.type === 'image') { | |
if (!token.attrs) { | |
token.attrs = []; | |
} | |
token.attrs.push(['loading', 'lazy']); | |
} else if ( | |
token.type === 'html_block' && |