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
td { | |
height: 50px; | |
width: 50px; | |
border: 1px solid gray; | |
text-align: center; | |
} |
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 checkNumSeq(sum, chunks) { | |
var | |
i, | |
hchunks, | |
chunk, | |
out = []; | |
if ( sum % chunks === 0 && chunks % 2 ) { | |
chunk = sum / chunks; |
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 invert(num) | |
rev = 0 | |
while num >= 10 | |
rev = (rev + num % 10) * 10 | |
num = fld(num, 10) | |
end | |
return (rev + num) | |
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 factorial(n) { | |
var | |
out = 1; | |
if ( n > 1 ) { | |
out = n * factorial(n - 1); | |
} | |
return out; |
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 setCountDown(n) { | |
n = n || 5; | |
for ( var i = 0; i <= n; i++ ) { | |
(function() { | |
var j = n - i; | |
setTimeout(function() { | |
console.log(j); | |
}, 1000 * i); | |
}()); | |
} |
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.method('inherits', function (parent) { | |
this.prototype = new parent(); | |
var d = {}, | |
p = this.prototype; | |
this.prototype.constructor = parent; | |
this.method('uber', function uber(name) { | |
if (!(name in d)) { | |
d[name] = 0; | |
} | |
var f, r, t = d[name], v = parent.prototype; |
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
// http://jsbin.com/mapena/edit?js,console | |
// http://stackoverflow.com/questions/1885557/simplest-code-for-array-intersection-in-javascript | |
function findIntersctions(a, b) { | |
var ai = 0; | |
var bi = 0; | |
var out = []; | |
while( ai < a.length && bi < b.length ) { | |
if( a[ai] > b[bi] ) { |
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 calcFromStr(str) { | |
var ops = ['*','/','+','-']; | |
var reg = /(\b\D)/; | |
var calc = str.split(reg); | |
function calculator(l, op, r) { | |
switch( op ) { | |
case '*': | |
return l*r; |
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 addClass(myElement, classToAdd) { | |
if (!myElement && !classToAdd) return; | |
var | |
myElementIsSting = typeof myElement == 'string', | |
myElementNode = myElementIsSting? document.getElementById(myElement): myElement, | |
classes = ' ' + (myElementNode.className || '') + ' ', | |
classToAdd = ' ' + classToAdd + ' '; | |
if (!~classes.indexOf(classToAdd)) { // http://stackoverflow.com/questions/12299665/what-does-a-tilde-do-when-it-precedes-an-expression |
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
// http://jsbin.com/ubugag/2/edit | |
var allDivs = document.getElementsByTagName("div"), | |
length = allDivs.length, divDomID, | |
showCarHandler = function(){ | |
var divDomINT = parseInt(this.id.replace("car_", 0), 10); | |
console.log(divDomINT); | |
}; | |
for(;length--;){ |