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
String.prototype.format = function(){ | |
var words = this.split(' '), | |
arg = arguments, | |
values = typeof arg[0]=='object'?arg[0]:arg,i; | |
for(i in words){ | |
if(words[i][0] == '%')words[i] = values[words[i].slice(1)]; | |
} | |
return words.join(' '); | |
} |
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
last = (new Date).getTime(); | |
str = ''; | |
for(i=0;i<100000;i++){ | |
str += ' Number ' + i; | |
} | |
print((new Date).getTime() - last) |
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
last = (new Date).getTime(); | |
str = ''; | |
for(i=0;i<100000;i++){ | |
str += 'Number %0'.format(i); | |
} | |
print((new Date).getTime() - last) |
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
String.prototype.format = function(){ | |
var words = this.split(' '), | |
arg = arguments, | |
values = typeof arg[0]=='object'?arg[0]:arg,i,str=''; | |
for(i in words){ | |
str += ' ' + (words[i][0] == '%'?values[words[i].slice(1)]:words[i]) | |
} | |
return 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
last = (new Date).getTime(); | |
str = ''; | |
for(a=0,b=0,c=0,d=0,f=0;a<1000,b<1000,c<1000,d<1000,f<1000;a++,b++,c++,d++,f++){ | |
str += 'Number %0 %1 %2 %3 %4'.format(a,b,c,d,f); | |
} | |
print((new Date).getTime() - last) | |
last = (new Date).getTime(); | |
str = ''; | |
for(a=0,b=0,c=0,d=0,f=0;a<1000,b<1000,c<1000,d<1000,f<1000;a++,b++,c++,d++,f++){ |
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
//Blocking scope | |
let(valuse){} | |
for(let values){} | |
//Tuples | |
(val1,val2) | |
//List expressions,range,reduce,guard | |
[a*a | list->a] | |
[1,3..33] |
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 Sequence(init,n,iter){ | |
return { | |
take:function(x){ | |
var list=init.slice(0); | |
while(x>list.length){ | |
list.push(iter.apply(null,(n!=Infinity?list.slice(list.length-n):list).concat(list.length))); | |
} | |
return list | |
}, | |
read:function(x){ |
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
Math.add = function(a,b){ | |
return a+b; | |
} | |
fib = Sequence([0,1],2,Math.add); | |
fib.take(20); | |
[0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181] | |
fib.read(15); |
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
Math.mult = function(a,b){ | |
return a*b; | |
} | |
fact = Sequence([1],1,Math.mult) | |
fact.take(20) | |
[1,1,2,6,24,120,720,5040,40320,362880,3628800,39916800,479001600,6227020800,87178291200,1307674368000,20922789888000,355687428096000,6402373705728000,121645100408832000] | |
fact.read(15) |
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(_){ | |
_.zip = function(){ | |
var i,u,res=[],list; | |
for(i=0;i<arguments[0].length;i++){ | |
list = []; | |
for(u=0;u<arguments.length;u++){ | |
list.push(arguments[u][i]); | |
} | |
res.push(list); | |
} |
OlderNewer