Skip to content

Instantly share code, notes, and snippets.

@konijn
konijn / index.html
Last active October 30, 2019 11:41 — forked from RomanPerekhrest/index.html
test_cycle #jsbench #jsperf (http://jsbench.github.io/#11a2b8507a7f9290c6ef6cda596f8179) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>test_cycle #jsbench #jsperf</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@konijn
konijn / compose.js
Created August 19, 2014 18:52
Compose
function merge(object, boltOn) {
//Simply merge the properties of boltOn into object
for(var property in boltOn)
if(boltOn.hasOwnProperty(property))
object[property] = boltOn[property];
return object;
}
function compose( /*Constructor1, Constructor2, ..*/ ) {
//Keep a closure reference for later
@konijn
konijn / Hmm.js
Last active August 29, 2015 14:03
var Hmm = (function()
{ //A snippet/library to find records in table-like JS arrays
function getNamedValue( o , name )
{ //Name can have dots, 'car.tire.brand.name' should get the expected
var parts = name.split(".");
while( parts.length && o ){
o = o[parts.shift()];
}
return o;
//Good
function lambdafy( f )
{
return function lambdafier() {
var args = Array.prototype.slice.call(arguments);
return function lambda(){
f.apply( this , args );
}
}
}
@konijn
konijn / template.js
Created February 7, 2014 14:29
Tiny Templates
function fillTemplate( s )
{ //Replace ~ with further provided arguments
for( var i = 1, a = s.split('~'), s = '' ; i < arguments.length ; i++ )
s = s + a.shift() + arguments[i];
return s + a.join("");
}
@konijn
konijn / powerSet.js
Last active January 4, 2016 00:39
powerSet
function powerSet( list ){
var set = [],
listSize = list.length,
combinationsCount = (1 << listSize);
for (var i = 1; i < combinationsCount ; i++ , set.push(combination) )
for (var j=0, combination = [];j<listSize;j++)
if ((i & (1 << j)))
combination.push(list[j]);
return set;
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="ISEE Math Challenge Generator" />
<meta charset=utf-8 />
<title></title>
</head>
<body>
</body>
function sortfunction(a, b)
{
return (a - b) //causes an array to be sorted numerically and ascending
}
function canWeDoIt( target , a )
{
if( a.length == 1 )
return (a[0] == target);
if( a[0] == target )
@konijn
konijn / permute.js
Created November 18, 2013 16:10
Permute
/* Permute will give all permutations for the provided array ( sourceSet )
do not provide usedSet nor permutationSet
Based on http://stackoverflow.com/a/9960925/7602
*/
function permute( sourceSet , usedSet , permutationsSet ) {
permutationsSet = permutationsSet || [];
usedSet = usedSet || [];
for (var i = 0; i < sourceSet.length; i++) {
usedSet.push( sourceSet.splice(i, 1)[0] );
if (!sourceSet.length)
@konijn
konijn / gist:7529404
Created November 18, 2013 15:13
Nicely format number in js
function formatNumber( n , precision )
{
n = n * 1;
return n.toLocaleString().split(".")[0] + "." + n.toFixed( precision || 2 ).split(".")[1];
}