Skip to content

Instantly share code, notes, and snippets.

View k-vosswinkel's full-sized avatar

Kait k-vosswinkel

View GitHub Profile

Clock Minute Adder


Interviewer Prompt

Given:

  • a time in string format HH:MM
  • a number of minutes

Return:

  • The time given those minutes added to the base time
@k-vosswinkel
k-vosswinkel / Eeny-Meeny-Game.js
Created July 6, 2018 02:43
A word problem & game
// You're playing a game in which you're given the number of players.
// Each turn, the player removes the person next to them.
// Play continues until there is only one player left.
// EXAMPLE: eenyMeeny(5) =>
// 1 2 3 4 5 <= round 1: player 1 (remove player 2)
// 1 3 4 5 <= round 2: player 3 (remove player 4)
// 1 3 5 <= round 3: player 5 (remove player 1)
// 3 5 <= round 4: player 3 (remove player 5)
// Player 3 is the winner!

Slides

Prompt

Implement an immutable binary search tree class. The class constructor should accept (at least) a single argument which will represent the value for its root node. Each instance should have two methods: insert, which takes a numerical value and returns a new binary search tree containing that value, and contains, which takes a numerical value and returns true or false based on whether the tree contains it.

Insert should not mutate the existing binary search tree. That is:

const bstA = new ImmutableBST(5);
@k-vosswinkel
k-vosswinkel / async-await-vs-promises-errors.js
Last active November 9, 2020 03:01
Playing with promises and async/await
const returnsAPromise = (string) => (
new Promise((resolve, reject) => {
if (typeof string !== 'string') reject('Not a string!');
resolve(`String is a resolved promise now: ${string}`);
})
);
const myString = "Kait's string";
let isOurPromiseFinished = false;
@k-vosswinkel
k-vosswinkel / database-promise.js
Created November 27, 2018 20:59
Promise handling a database call
const queryADatabase = function(mysql, query) {
return new Promise((resolve, reject) => {
mysql.query(query, (err, rows) => {
if (err) reject(err);
else resolve(rows);
});
})
};
/* What we're doing here is creating a promise that resolves or rejects
/* eslint-disable no-unused-vars */
const rotater = str => {
let flip = false;
let rotatedStr;
return function (steps) {
if (steps === str.length) {
flip = !flip;
}