Skip to content

Instantly share code, notes, and snippets.

View BenDMyers's full-sized avatar
🦖

Ben Myers BenDMyers

🦖
View GitHub Profile
@BenDMyers
BenDMyers / cap-permutations.js
Created January 10, 2022 07:27
RWC: Cap Permutations
/**
* 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
@BenDMyers
BenDMyers / validate-wordle-guess.js
Last active January 15, 2022 17:56
Wordle Validation Script
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}[]}
*/
@BenDMyers
BenDMyers / wordle-validation.js
Created January 17, 2022 04:51
RWC Wordle Validation
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 and returns emoji string
* @param {string} guess five-letter guess (presumes the guess has already been through other formatting validations like length and valid characters)
* @param {string} solution the target word the player is trying to guess
* @returns {string} emoji sequence
*/
@BenDMyers
BenDMyers / equal-with-deletions.js
Created April 5, 2022 01:39
RWC: Equal With Deletions
/**
* Evaluate a string's results after backspaces and forward deletions.
* A `#` is a backspace, removing the previous undeleted character.
* A `%` is a forward deletion, removing the next letter.
* @param {string} str
* @returns {string} provided string, with deleted characters removed
*/
function evaluateString(str) {
const characters = str.split('');
@BenDMyers
BenDMyers / maximized-array.js
Created May 16, 2022 14:58
RWC: Maximized Array
/**
* Comparison function for two integers which will sort the bigger one first
* @param {number} int1
* @param {number} int2
*/
function bySize(int1, int2) {
return int2 - int1;
}
/**
@BenDMyers
BenDMyers / start-to-end.js
Created May 25, 2022 03:07
RWC: Start to End
const ORIGIN = 1;
const DESTINATION = 2;
const WALL = 3;
/**
* @typedef {{
* coordinates: string,
* distanceFromOrigin: number,
* shortestPaths: Direction[][]
* }} DjikstraNode
@BenDMyers
BenDMyers / all-unique.js
Last active May 30, 2022 09:13
RWC: All Unique
/**
* Determines whether all characters in a string are unique.
*
* Original question:
* **Write a function that determines if all the characters in a given string are unique.**
* Can you do this without making any new variables? You choose if you want to include
* capitalization in your consideration for this one, as a fun challenge.
*
* @param {string} str string to test
* @param {boolean} [caseSensitive] whether to take capitalization into account
@BenDMyers
BenDMyers / previous-fibonacci.js
Created June 20, 2022 15:19
RWC: Previous Fibonacci Number
/**
* Gets the previous number in the Fibonacci sequence, or -1 if this number isn't in the sequence
* @param {number} num
* @returns {number} previous Fibonacci number (or -1)
*/
function getPreviousFibonacciNumber(num) {
// Handle negatives
if (num <= 0) {
return -1;
}
@BenDMyers
BenDMyers / longest-word.js
Created June 27, 2022 05:24
RWC: Longest Word That's a Subsequence
/**
* Comparison function for sorting an array of strings by length
* @param {string} a first word from dictionary
* @param {string} b second word from dictionary
* @return {number} relative order of the two strings
*/
function byLength(a, b) {
return b.length - a.length;
}
@BenDMyers
BenDMyers / card.css
Created August 22, 2022 17:07
Anthony's Social Card Styles
html {
--blue: #61DBFB;
--blue-dark: #1d8099;
font-family: Raleway;
margin: 0;
}
body {
margin: 0;
height: 100vh !important;