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
// chaining functions | |
var flag = 0; | |
var list = [ | |
function(f){}, | |
function(f){}, | |
function(f){}, | |
function(f){ flag = f; } | |
]; |
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
// Creating simple objects. | |
// our constructors | |
var A = function(){}; | |
var B = function(){}; | |
B.prototype.m = function(){}; | |
var C = function(){ | |
this.p = 42; | |
}; | |
C.prototype.m = function(){}; |
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
#Newbie programmer | |
def factorial(x): | |
if x == 0: | |
return 1 | |
else: | |
return x * factorial(x - 1) | |
print factorial(6) | |
#First year programmer, studied Pascal |
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
// Benchmarking summation of array | |
var a = []; | |
for(var i = 0; i < 100; ++i) a.push(Math.random()); | |
this.group( | |
"Iterations", | |
function classic(){ | |
for(var sum = 0, i = 0, l = a.length; i < l; ++i){ sum += a[i]; } | |
}, |
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
// Benchmarking different ways to call a function. | |
var context = {}, fb = null; | |
function test(){} | |
this.group( | |
"Calling function", | |
function Normal(x){ return test(x); }, | |
{ | |
name: "Function.call()", | |
test: function(x){ return test.call(context, x); } |
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
// How to format big numbers using commas to separate 1000s and abbreviations | |
// Example: 12345678900 => 12.34B | |
var numPattern = /^(\d{0,2})(\d{3})?(\d{3})?(\d{3})?(\d{3})?(\d{3})?(\d{3})?(\d{3})?(\d{3})?(\d{3})?(\d{3})?$/; | |
function putCommasIn(s){ | |
return s.match(numPattern).slice(1).join(",").replace(/^\,{1,}/, "").replace(/\,{1,}$/, ""); | |
} | |
function trimZeroes(s){ | |
return s.replace(/\.?0+$/, ""); |
NewerOlder