Skip to content

Instantly share code, notes, and snippets.

View SH4DY's full-sized avatar

Ramon SH4DY

View GitHub Profile
@SH4DY
SH4DY / rand5.js
Last active October 10, 2016 02:13
rand5() - Weekly interview question from interview cake
/*
You have a function rand7() that generates a random integer from 1 to 7.
Use it to write a function rand5() that generates a random integer from 1 to 5.
rand7() returns each integer with equal probability.
rand5() must also return each integer with equal probability.
*/
function rand5(){
var x = rand7();
while(x > 5){
@SH4DY
SH4DY / LibDependencies.js
Last active August 29, 2015 14:17
Library dependencies - Graph topological sorting per DFS
//Topological sorting - Example of library dependencies
//Imagine you are given library dependencies in this form in a FILE:
// 4 libraries, 5 dependencies
// 0 -> 1
// 1 -> 2
// 2 -> 3
// 2 -> 4
// 3 ->
// 4 ->
// Meaning library 0 depends on lib 1...lib 3 depends on nothing etc
@SH4DY
SH4DY / 0_reuse_code.js
Last active August 29, 2015 14:16
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console