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
//Merge Sort | |
Array.prototype.mergeSort = function() { | |
var thiz = this; | |
if (this.length <= 1) { | |
return this; | |
} | |
//split left and right | |
var left = [], right = []; |
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
//JS QuickSort | |
Array.prototype.quickSort = function() { | |
var r = this; | |
if(this.length <= 1) { | |
return this; | |
} | |
var less = [], greater = []; |
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
/* Rotate an array n positions | |
* if n is positive - rotate to the left | |
* if n is negative - rotate to the right | |
*/ | |
Array.prototype.rotate = function(n) { | |
//Make a copy of the current array | |
var newArray = this.slice(0); | |
//Handle a number greater than the length so that it loops around |
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
git for-each-ref --sort=-committerdate refs/heads/ |
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
function Deferred () { | |
var rand = Math.random(); | |
var dones = []; | |
var is_resolved = false; | |
return { | |
promise: function () { | |
}, | |
resolve: function(str) { |
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
function allUnique(str) { | |
var a = []; | |
for (var i = 0; i < str.length; i++) { | |
var char = str.charAt(i); | |
if (!a[char]) { | |
a[char] = true; | |
} else { | |
return false; | |
} |
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
function Node(d) { | |
this.next = undefined; | |
this.data = d; | |
this.appendToTail = function(d) { | |
var end = new Node(d); | |
var n = this; | |
while (n.next !== undefined) { n = n.next; } | |
n.next = end; |
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
function Stack() { | |
var data = []; | |
var stackPtr = [0,0,0]; | |
this.push = function(stackNumber, d) { | |
var index = stackNumber + stackPtr[stackNumber] * 3; | |
data[index] = d; | |
stackPtr[stackNumber]++; | |
}; | |
this.print = function() { | |
var strs = ["","",""]; |
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
.slot { | |
padding: 3px; | |
text-align: center; | |
border: 0; | |
} | |
.available { | |
background-color: #eee; | |
} |
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
function mergeSort(arr) { | |
for (var n = 1; n < 4 ; n++){ | |
var seg_size = Math.pow(2, n); | |
for (var seg = 0; seg < Math.ceil(arr.length/seg_size); seg++) { | |
var before = arr.slice(0, seg * seg_size); | |
var cur = arr.slice(seg * seg_size, (seg+1) * seg_size); | |
var after = arr.slice((seg+1) * seg_size); | |
var left = cur.slice(0, seg_size/2); |
OlderNewer