Skip to content

Instantly share code, notes, and snippets.

View BenDMyers's full-sized avatar
🦖

Ben Myers BenDMyers

🦖
View GitHub Profile
@BenDMyers
BenDMyers / unique-substring.js
Last active April 15, 2024 14:04
[RWC] uniqueSubstr
/**
* Sorter function for sorting an array of strings by their length, in descending order
* @param {string} a
* @param {string} b
* @returns positive/negative number representing relative comparison of the two elements
*/
function byLength(a, b) {
return b.length - a.length;
}
@BenDMyers
BenDMyers / largest-island.js
Created March 25, 2024 15:05
[RWC] Largest Island 🏝️
/**
* @typedef {(0 | 1)[][]} IslandInput
*/
/**
* @typedef {Object} Island
* @property {string[]} coordinates
*/
/**
@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;
@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 / 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 / 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 / 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 / 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 / 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 / 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
*/