Skip to content

Instantly share code, notes, and snippets.

View deyles-zz's full-sized avatar

deyles deyles-zz

  • Sydney, Australia
View GitHub Profile
@deyles-zz
deyles-zz / gist:5812044
Created June 19, 2013 06:19
... and recursive merge sort...
function merge(left, right) {
var merged = left.slice(0);
right.forEach(function(element) {
var i = merged.length - 1;
var m = false;
for (; i >= 0; i--) {
if (merged[i] <= element) {
merged.splice(i+1, 0, element);
m = true;
break;
@deyles-zz
deyles-zz / gist:5811999
Created June 19, 2013 06:05
That moment when you realize you can write recursive quick sort from memory...
function quicksort(elements) {
if (elements.length <= 1) {
return elements;
}
var left = [];
var right = [];
var middle = Math.floor(elements.length/2);
var element = null;
var pivot = elements[middle];
@deyles-zz
deyles-zz / gist:5796984
Last active December 18, 2015 14:28
I got asked this interview question and thought it was interesting. I was trying to write the answer on paper and completely buggered it up, but it was pretty easy to solve after the fact (a few beers helped :-P).
Given an array of numbers figure out the top 5 numbers. Return the result as an array.
Scoring is done thusly:
* All numbers >= 1 are worth +1 point
* All zeroes are worth -2
* Numbers with digits in ascending order get +5 points (e.g. [3, 4, 4, 5])
@deyles-zz
deyles-zz / gist:2965438
Created June 21, 2012 12:15
JSONDB example showing how to build TableView rows
var jsondb = require("com.irlgaming.jsondb");
var collection = jsondb.factory("test","yoursharedsecrethere");
// grab all records with a value of greater than or equal to 10 for the attribute "i"
// with a limit of 200
var o = collection.find({i:{$gte:10}, {limit:200});
// tuples in the result look something like:
/*
{