This file contains hidden or 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
scale = function(a,d) { return a.map(function(x) { return (x - avg(a)) / d}) } | |
avg = function(a) { return sum(a) / a.length } | |
sum = function(a) { return a.reduce(function(x,y) { return x + y; }) } | |
max = function(a) { return a.sort(function(x,y) { return x < y; })[0] } | |
min = function(a) { return a.sort(function(x,y) { return x > y; })[0] } | |
sd = function(a,av) { return Math.sqrt(avg(a.map(function(x) { return (x - av) * x; }))); } | |
z = [20,25,10,33,50,42,19] | |
scale(z,(max(z) - min(z))) // [-0.2107142857142857, -0.23571428571428568, -0.2107142857142857, -0.08571428571428567, 0.11428571428571432, 0.3392857142857143, 0.5392857142857144] |
This file contains hidden or 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
Object.prototype.isEqual = function(obj) { | |
function iter(a, b) { | |
for(p in a) { | |
if(a.hasOwnProperty(p)) { | |
if(!b.hasOwnProperty(p)) return false; | |
else if(['array', 'object'].indexOf(typeof b[p]) > -1) { | |
if(!iter(b[p], a[p])) return false; |
This file contains hidden or 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
Sorting = { | |
insert_sort: function(xs) { | |
function insert(x, xs) { | |
if(xs.length === 0) return [x]; | |
else return x <= xs[0] ? [x].concat(xs) : [xs[0]].concat(insert(x, xs.slice(1))); | |
} | |
return xs.length === 0 ? [] : insert(xs[0], this.insert_sort(xs.slice(1))); |
This file contains hidden or 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
var Empty = { | |
contains: function(x) { return false; }, | |
incl: function(x) { return new NonEmpty(x, Empty, Empty); }, | |
union: function(other) { return other; }, | |
toString: function() { return '.'; } | |
}; | |
var NonEmpty = function(elem, left, right) { | |
return { |
This file contains hidden or 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
var List = function() { | |
return (function build(xs) { | |
if(xs.length === 0) return Nil | |
return new Cons(xs[0], build(Array.prototype.slice.call(xs, 1))); | |
})(arguments); | |
} | |
var Nil = { | |
head: null, | |
tail: null, |
This file contains hidden or 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
Array.prototype.multimap = function(f) { | |
return this.length == 0 ? [] : [(this[0] instanceof Array ? this[0].multimap(f) : f(this[0]))].concat(this.slice(1).multimap(f)); | |
} | |
Array.prototype.multireduce = function(f, z) { | |
return this.length == 0 ? z : f((this[0] instanceof Array ? this[0].multireduce(f, z) : this[0]), this.slice(1).multireduce(f, z)); | |
} |
This file contains hidden or 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($) { | |
$.event.special.tripleclick = { | |
clicked: 0, | |
time: 0, | |
threshold: 80, | |
setup: function() { | |
$(this).on('click', $.event.special.tripleclick.handler); |
This file contains hidden or 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($) { | |
$.fn.zoomblo = function(full) { | |
$(this).css({ | |
position: 'relative', | |
overflow: 'hidden' | |
}); | |
var org = { |
This file contains hidden or 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
// O(n log n) | |
Array.prototype.submax = function() { | |
if(this.length === 0) return 0; | |
if(this.length === 1) return this[0]; | |
var m = Math.floor(this.length / 2); | |
var max_left = find_max(this, m - 1, 0); | |
var max_right = find_max(this, m, this.length); |
This file contains hidden or 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
// O(n) | |
Array.prototype.submax = function() { | |
var max = sum = 0; | |
for(var i = 0, l = this.length; i < l; i++) { | |
sum = Math.max(sum + this[i], 0); | |
max = Math.max(max, sum); | |
} | |
return max; | |
} |