MINI Sh3ll
// Removes duplicates from an array.
function unique(array) {
return $.grep(array, function(el, index) {
return index === $.inArray(el, array);
});
}
// Round a value to the closest 'to'.
function closest ( value, to ) {
return Math.round(value / to) * to;
}
// Checks whether a value is numerical.
function isNumeric ( a ) {
return typeof a === 'number' && !isNaN( a ) && isFinite( a );
}
// Rounds a number to 7 supported decimals.
function accurateNumber( number ) {
var p = Math.pow(10, 7);
return Number((Math.round(number*p)/p).toFixed(7));
}
// Sets a class and removes it after [duration] ms.
function addClassFor ( element, className, duration ) {
element.addClass(className);
setTimeout(function(){
element.removeClass(className);
}, duration);
}
// Limits a value to 0 - 100
function limit ( a ) {
return Math.max(Math.min(a, 100), 0);
}
// Wraps a variable as an array, if it isn't one yet.
function asArray ( a ) {
return $.isArray(a) ? a : [a];
}
// Counts decimals
function countDecimals ( numStr ) {
var pieces = numStr.split(".");
return pieces.length > 1 ? pieces[1].length : 0;
}
OHA YOOOO