Skip to content

Instantly share code, notes, and snippets.

View earlonrails's full-sized avatar

Kevin Krauss earlonrails

  • Disney Streaming
  • San Francisco
View GitHub Profile
@earlonrails
earlonrails / HourGlass.js
Last active July 2, 2018 12:11
Solution to 2D array problem from hackerrank in ES6 - https://www.hackerrank.com/challenges/2d-array/problem
#!/usr/bin/env node
// https://www.hackerrank.com/challenges/2d-array/problem
class HourGlass {
constructor(attrs, debug) {
this.attrs = attrs
this.debug = debug
this.value = this.compute()
}
@earlonrails
earlonrails / shortestPath.js
Last active November 26, 2023 09:34
shortest path and bfs in es6 javascript
#!/usr/bin/env node
// Question found here:
// https://stackoverflow.com/questions/32527026/shortest-path-in-javascript
// Based on the first accepted answer
"use strict"
const expect = require('expect.js')
class Graph {
constructor(props) {
this.neighbors = {}
@earlonrails
earlonrails / mergeSort.js
Created July 24, 2017 21:56
MergeSort in es6!
#!/usr/bin/env node
"use strict"
const expect = require('expect.js')
class MergeSort {
static sort(array) {
let mid = array.length / 2
let left = array.slice(0, mid)
let right = array.slice(mid)
@earlonrails
earlonrails / pocketChange.js
Last active July 24, 2017 21:53
Sort some pocket change in es6!
#!/usr/bin/env node
"use strict"
const expect = require('expect.js')
const coinTypes = {
"0.01": "Pennies",
"0.05": "Nickels",
"0.10": "Dimes",
"0.25": "Quarters",
"0.50": "Quarters",
@earlonrails
earlonrails / merkle.js
Last active July 26, 2017 20:19
Merkle tree written in es6 javascript
#!/usr/bin/env node
"use strict"
const expect = require('expect.js')
class Merkle {
constructor(array) {
this.key = array.join('')
this.left = null
this.right = null
@earlonrails
earlonrails / throttle.js
Last active April 25, 2017 18:16
throttle a function call in javascript
#!/usr/bin/env node
"use strict"
function throttle(fn, limitInMs) {
var count = 0;
return function () {
var context = this, args = arguments;
console.log("waiting: ", limitInMs * count, "ms")
setTimeout(function () {
#!/usr/bin/env node
"use strict"
// Write a function that receives a position in 2 dimensional (x,y) array, which was initially initialized with 'o' (signals "water"), the function changes the value/state of that position to 'x' (signals "land") and returns the number of isles in the board.
// For example, for 3x3 board, it will initially look like the following:
// o o o
// o o o
// o o o
// After calling the function with the position (1,2), the board will look like the following:
// o o x
#!/usr/bin/env node
"use strict"
class Quicksort extends Array {
// swap the value in the leftIdx with the value in the rightIdx
swap(leftIdx, rightIdx) {
let old = this[leftIdx]
this[leftIdx] = this[rightIdx]
this[rightIdx] = old
}
@earlonrails
earlonrails / CircularArray.js
Created February 22, 2017 02:15
circular array javascript es6 hackerrank question #spoiler
#!/usr/bin/env node
"use strict"
class CircularArray {
constructor(n, k, q, arr, debug = false) {
this.n = n // number of integers
this.k = k // rotations
this.q = q // queries
this.arr = arr
this.debug = debug
@earlonrails
earlonrails / findComments.js
Created February 13, 2017 00:50
Find all the comments in the java code, I did the answer in javascript though
#!/usr/bin/env node
"use strict"
// https://www.careercup.com/question?id=5663127975755776
// Find all comments in the Java (it could be Python or any other language of your choice) codes that’s parsed in as a string.
// You may assume the codes given is valid.
// Input is a single string, e.g.
// String codes =
// “/* file created by aonecode.com\\n” +