The documentation is live and interactive powered by the KLIPSE plugin:
JST
from the javascript-toolbelt github repository (It might take a couple of seconds...):
Object.keys(JST)
system_time
returns highest resolution time offered by host in milliseconds.
JST.system_time()
time
returns a string with the number of msec resolution time offered by host in milliseconds.
JST.time(function(){
Math.sqrt(1232);
})
benchmark
returns a string with the number of msec to run a function n
times.
JST.benchmark(100, function(){
Math.sqrt(1232);
})
permutations
is a handy function that returns the permutations of an array.
Thank you StackOverflow!
JST.permutations([1,2,3])
And it is quite fast. You can judge by yourself:
JST.time(function() { return JST.permutations([1,2,3,4]);})
memoize
returns a memoized version of a 1-arity
function.
memo = JST.memoize(JST.permutations);
[
JST.time(function() {
JST.permutations([1,2,3,4,5]);
}),
JST.time(function() {
memo([1,2,3,4,5]);
}),
JST.time(function() {
memo([1,2,3,4,5]);
})
]
memo
takes about the same time as the direct call to JST.permutations
.
But subsequent calls are very fast.
maxBy
returns the element of the array that leads to the greatest value.
Thanks StackOverflow!
JST.maxBy(function(s) { return s.length;}, ['albatross', 'dog', 'horse'])
minBy
returns the element of the array that leads to the greatest value.
JST.minBy(function(s) { return s.length;}, ['albatross', 'dog', 'horse'])
flattenObject
returns an object with the keys flattened.
JST.flattenObject({
x: 1,
y: {z: 2, w: [3, 4]}
})
minBy
returns the element of the array that leads to the greatest value.