This file contains 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
#!/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() | |
} |
This file contains 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
#!/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 = {} |
This file contains 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
#!/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) |
This file contains 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
#!/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", |
This file contains 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
#!/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 |
This file contains 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
#!/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 () { |
This file contains 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
#!/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 |
This file contains 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
#!/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 | |
} |
This file contains 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
#!/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 |
This file contains 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
#!/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” + |