Namespace: core

algo. core

Source:

Classes

Array
DataStructure
Graph
GraphEdge
GraphVertex
Heap
PixelBuffer

Methods

<static> binarySearchArray(a, v, c) → {*}

Perform a binary search on the given array for the value, using the optional comparator. If searching for zero, empty strings or other falsey objects you will need to compare against null e.g. if (_.isNull(algo.core.binarySearchArray(a, 0))) { //not found }
Parameters:
Name Type Argument Description
a Array
v * the object/value to search for
c function <optional>
optional comparator
Source:
Returns:
Type
*

<static> compare(a, b, comparator) → {boolean}

Compare arrays values and length. Unequal length arrays are considered different
Parameters:
Name Type Argument Description
a Array first array to compare
b Array second array to compare
comparator function <optional>
optional comparator function
Source:
Returns:
Type
boolean

<static> compareItems(a, b, comparator) → {number}

Compare two items ( of the same type ) using either the supplied comparison function or the javascript ===/< operators
Parameters:
Name Type Argument Description
a Object | number | string first of two objects to compare
b Object | number | string second of two objects to compare
comparator function <optional>
optional function for comparing a and b
Source:
Returns:
Type
number

<static> copyArray(a, start, end) → {Array}

return a new array with the given subsection of the array start->end-1
Parameters:
Name Type Argument Description
a Array
start number <optional>
optional, zero if not supplied
end number <optional>
optional, length of array if not supplied
Source:
Returns:
Type
Array

<static> copyArrayEnd(a, n) → {Array}

return a new array with the last n values from a
Parameters:
Name Type Description
a Array
n number
Source:
Returns:
Type
Array

<static> copyArrayStart(a, n) → {Array}

return a new array with the first values from a
Parameters:
Name Type Description
a Array
n number
Source:
Returns:
Type
Array

<static> createMultiArray() → {Array}

create a multi-dimensional array, where the length of each dimension is specified by one of the arguments e.g. var a = createMD(2,2,2); a[1][1][1] = 3.14; var a = createMD(1,2,3,4); a[0][1][2][3] = "1234";
Parameters:
Name Type Description
(...dimensions) zero to n dimensions for the array
Source:
Returns:
Type
Array

<static> degreesToRadians(d) → {number}

degrees to radian conversion
Parameters:
Name Type Description
d number
Source:
Returns:
Type
number

<static> extends(progenitor, progeny)

This is the most basic way to implement class inheritance in JavaScript. The prototype property of the progeny class ( the new class ) is simply copied from the prototype property if the progenitor class ( the base class ). After that we simple ensure that the correct constructor function is called when creating new instances of progeny.
Parameters:
Name Type Description
progenitor function the base class ( constructor )
progeny function the extended ( inheriting ) class ( constructor )
Source:

<static> factorial(n) → {number}

recursive method for calculating the factorial of a positive integer
Parameters:
Name Type Description
n number a positive integer
Source:
Returns:
Type
number

<static> fillArray(a, value, step) → {*}

fill the array with values starting a zero and incrementing by step or zero if not supplied.
Parameters:
Name Type Argument Description
a Array
value number
step number <optional>
optional increment to add to value each time
Source:
Returns:
Type
*

<static> hasAny(obj)

return true if obj has any of the properties in the variable argument list
Parameters:
Name Type Description
obj
(...properties) properties to test
Source:

<static> hasProperties(obj)

return true if obj has all the properties in the variable argument list
Parameters:
Name Type Description
obj
(...properties) properties to test
Source:

<static> isCircleLike(obj) → {boolean}

true if the obj has circle like properties ( x/y/radius )
Parameters:
Name Type Description
obj object the object to test
Source:
Returns:
Type
boolean

<static> isEmptyArray(a) → {boolean}

returns true if the object is an array of zero length
Parameters:
Name Type Description
a Array the array to test
Source:
Returns:
Type
boolean

<static> isLineLike(obj) → {boolean}

true if the obj has line properties ( x1/y1/x2/y2 )
Parameters:
Name Type Description
obj object the object to test
Source:
Returns:
Type
boolean

<static> isPointLike(obj) → {boolean}

true if the obj has point line properties ( x/y )
Parameters:
Name Type Description
obj object the object to test
Source:
Returns:
Type
boolean

<static> isRectLike(obj) → {boolean}

true if the obj has rectangle line properties ( x/y/w/h )
Parameters:
Name Type Description
obj object the object to test
Source:
Returns:
Type
boolean

<private, static> merge(a, b) → {Array}

The merge function for algo.core.mergeSort
Parameters:
Name Type Description
a Array the first array to merge
b Array the second array to merge
Source:
Returns:
- the sorted combination of a + b
Type
Array

<static> mergeSortArray(a) → {Array}

Merge sort the entire array. NOTE: This is not an in place merge sort and is therefore not optimal. Also it always sorts the entire array. Use quickSort for a more space efficient algorithm or when you want to sort a sub section of the array. NOTE: This method only works with native Array types since it uses slice on the array
Parameters:
Name Type Description
a Array the array to sort
Source:
Returns:
- a new sorted array
Type
Array

<static> pointOnEllipse(cx, cy, radiusX, radiusY, degrees) → {Object}

returns a point on an ellipse centered at cx/cy with given x/y radius.
Parameters:
Name Type Description
cx number
cy number
radiusX number
radiusY number
degrees number
Source:
Returns:
Type
Object

<static> quickSortArray(a, start, end, comparator)

In place quickSort (partition sort). Call with 0, array.length to sort the entire array, or provide a sub section to sort.
Parameters:
Name Type Argument Description
a Array the array to sort
start number start of section to sort
end number end of section to sort
comparator function <optional>
optional comparator for items
Source:

<private, static> quickSortPartition(a, left, right, comparator) → {*}

internal partition method for quickSort
Parameters:
Name Type Description
a
left
right
comparator
Source:
Returns:
Type
*

<static> radiansToDegrees(r) → {number}

radians to degree conversion
Parameters:
Name Type Description
r number
Source:
Returns:
Type
number

<static> random(seed) → {random}

a predictable random number generator. You can either use a replacement for Math.random or just monkey patCh Math.random e.g. Math.random = algo.core.random(); Large, prime numbers are the best seed but anything > 0 will work This method returns random number generator, not a random number! e.g. var r = algo.core.random(); var x = r();
Parameters:
Name Type Description
seed
Source:
Returns:
Type
random

<static> randomFloat(min, max, _rgen) → {function}

returns a generator for random floats in the range min -> max - 1 It make it predictable supply algo.core.random() or it will use Math.random() For example to generate random array indices... var a = [1,2,3,4,5,6,7,8,9,10]; var r = algo.core.randomInteger(0, a.length);
Parameters:
Name Type Argument Description
min number
max number
_rgen function <optional>
a function that returns a random number between 0..1
Source:
Returns:
Type
function

<static> randomInteger(min, max, _rgen) → {function}

returns a generator for random integers in the range min -> max - 1 It make it predictable supply algo.core.random() or it will use Math.random() For example to generate random array indices... var a = [1,2,3,4,5,6,7,8,9,10]; var r = algo.core.randomInteger(0, a.length);
Parameters:
Name Type Argument Description
min number
max number
_rgen function <optional>
a function that returns a random number between 0..1
Source:
Returns:
Type
function

<static> randomizeArray(a, min, max, seed) → {Array}

fill the array with random values between min and max using the optional random number seed
Parameters:
Name Type Argument Description
a Array
min number
max number
seed number <optional>
optional seed
Source:
Returns:
Type
Array

<static> reverseArray(a, start, end)

reverse the subsection of the array or the entire array if start, end not supplied
Parameters:
Name Type Description
a
start
end
Source:

<static> reverseString(s) → {string}

One of several ways to reverse a string in javascript. Works by first splitting into an array of strings of length 1 ( since javascript does not have a char type ) and then reverse the array and join back together as a string.
Parameters:
Name Type Description
s string the string to reverse
Source:
Returns:
s reversed
Type
string

<static> shuffleArray(a) → {*}

fisher yates shuffle of an array, defer implemention to underscore
Parameters:
Name Type Description
a
Source:
Returns:
Type
*

<static> sortLetters(s) → {*}

sort the string using the standard lexographical order e.g. "Seven minus Two is 5!" returns " !5STeeiimnnossuvw"
Parameters:
Name Type Description
s
Source:
Returns:
Type
*

<static> stringToArray(s) → {Array|*}

although JavaScript strings have array like properties they are not true arrays. This returns the string as a native array
Parameters:
Name Type Description
s string
Source:
Returns:
Type
Array | *

<static> swapArray(a, x, y)

swap two elements in an array
Parameters:
Name Type Description
a Array
x number
y number
Source:

<static> swapProperties(p, a, b)

swap the property p of objects a and b
Parameters:
Name Type Description
p
a
b
Source: