Skip to content

General Purpose Functions

dan-eyles edited this page Jul 25, 2013 · 3 revisions

cloneObject ( object[Object] )

Performs a deep clone of an object, returning a reference to the clone

var o = {
   foo:'bar',
   bar: {
      array: [0, 1, 2, 3, 4]
   }
};
var clone = Scule.global.functions.cloneObject(o);

sizeOf ( object[Mixed] )

Returns the length (number of keys/elements) of the provided object as an integer value. This function supports Objects, Strings, and Arrays as valid arguments.

var string = 'abcdefg';
var array  = [0, 1, 2, 3, 4];
var object = {a:1, b:2, c:3, d:4};
Scule.global.functions.sizeOf(string); // 7
Scule.global.functions.sizeOf(array); // 5
Scule.global.functions.sizeOf(object); // 4

shuffle ( array[Array] )

Shuffles the provided array in place - this function does not preserve keys in associative arrays.

var a = [0, 1, 2, 3, 4, 5];
Scule.global.functions.shuffle(a); // value of a is now [4, 2, 0, 1, 3, 5] - or some other random order

isArray ( object[Mixed] )

Returns a boolean value indicating whether or not the provided object is an instance of the Array class.

isInteger ( object[Mixed] )

Returns a boolean value indicating whether or not the provided object is an integer.

isDouble ( object[Mixed] )

Returns a boolean value indicating whether or not the provided object is a floating point number.

isScalar ( object[Mixed] )

Returns a boolean value indicating whether or not the provided value is scalar.

randomFromTo ( from[Number], to[Number] )

Returns a random integer between the two provided range bounds.

var random = Scule.global.functions.randomFromTo(1, 10);