ArrayHelper

SmilesDrawer. ArrayHelper

A static class containing helper functions for array-related tasks.

Constructor

new ArrayHelper()

Source:

Methods

(static) clone(arr) → {*}

Source:

Clone an array or an object. If an object is passed, a shallow clone will be created.

Parameters:
Name Type Description
arr *

The array or object to be cloned.

Returns:

A clone of the array or object.

Type
*

(static) contains(arr, options) → {Boolean}

Source:

Checks whether or not an array contains a given value. the options object passed as a second argument can contain three properties. value: The value to be searched for. property: The property that is to be searched for a given value. func: A function that is used as a callback to return either true or false in order to do a custom comparison.

Parameters:
Name Type Description
arr Array

An array.

options Object

See method description.

Properties
Name Type Attributes Description
property String

The property on which to check.

value *

The value for which to check.

func function <optional>

A custom property function.

Returns:

A boolean whether or not the array contains a value.

Type
Boolean

(static) containsAll(arrA, arrB) → {Boolean}

Source:

Checks whether or not an array contains all the elements of another array, without regard to the order.

Parameters:
Name Type Description
arrA Array

An array.

arrB Array

An array.

Returns:

A boolean indicating whether or not both array contain the same elements.

Type
Boolean

(static) count(arr, value) → {Number}

Source:

Count the number of occurences of a value in an array.

Parameters:
Name Type Description
arr Array

An array.

value *

A value to be counted.

Returns:

The number of occurences of a value in the array.

Type
Number

(static) deepCopy(arr) → {Array}

Source:

Copies a an n-dimensional array.

Parameters:
Name Type Description
arr Array

The array to be copied.

Returns:

The copy.

Type
Array

(static) each(arr, callback)

Source:

Run a function for each element in the array. The element is supplied as an argument for the callback function

Parameters:
Name Type Description
arr Array

An array.

callback function

The callback function that is called for each element.

(static) get(arr, property, value) → {*}

Source:

Return the array element from an array containing objects, where a property of the object is set to a given value.

Parameters:
Name Type Description
arr Array

An array.

property String | Number

A property contained within an object in the array.

value String | Number

The value of the property.

Returns:

The array element matching the value.

Type
*

(static) intersection(arrA, arrB) → {Array}

Source:

Returns an array containing the intersection between two arrays. That is, values that are common to both arrays.

Parameters:
Name Type Description
arrA Array

An array.

arrB Array

An array.

Returns:

The intersecting vlaues.

Type
Array

(static) merge(arrA, arrB) → {Array}

Source:

Merges two arrays and returns the result. The first array will be appended to the second array.

Parameters:
Name Type Description
arrA Array

An array.

arrB Array

An array.

Returns:

The merged array.

Type
Array

(static) print(arr) → {String}

Source:

Returns a string representation of an array. If the array contains objects with an id property, the id property is printed for each of the elements.

Parameters:
Name Type Description
arr Array.<Object>

An array.

Properties
Name Type Description
id *

If the array contains an object with the property 'id', the properties value is printed. Else, the array elements value is printend.

Returns:

A string representation of the array.

Type
String

(static) remove(arr, value) → {Array}

Source:

Remove a value from an array.

Parameters:
Name Type Description
arr Array

An array.

value *

A value to be removed.

Returns:

A new array with the element with a given value removed.

Type
Array

(static) removeAll(arrA, arrB) → {Array}

Source:

Remove all elements contained in one array from another array.

Parameters:
Name Type Description
arrA Array

The array to be filtered.

arrB Array

The array containing elements that will be removed from the other array.

Returns:

The filtered array.

Type
Array

(static) removeUnique(arr, value) → {Array}

Source:

Remove a value from an array with unique values.

Parameters:
Name Type Description
arr Array

An array.

value *

A value to be removed.

Returns:

An array with the element with a given value removed.

Type
Array

(static) sortByAtomicNumberDesc(arr) → {Array.<Object>}

Source:

Sort an array of atomic number information. Where the number is indicated as x, x.y, x.y.z, ...

Parameters:
Name Type Description
arr Array.<Object>

An array of vertex ids with their associated atomic numbers.

Properties
Name Type Description
vertexId Number

A vertex id.

atomicNumber Number

The atomic number associated with the vertex id.

Returns:

The array sorted by atomic number. Example of an array entry: { atomicNumber: 2, vertexId: 5 }.

Type
Array.<Object>

(static) toggle(arr, value) → {Array}

Source:

Toggles the value of an array. If a value is not contained in an array, the array returned will contain all the values of the original array including the value. If a value is contained in an array, the array returned will contain all the values of the original array excluding the value.

Parameters:
Name Type Description
arr Array

An array.

value *

A value to be toggled.

Returns:

The toggled array.

Type
Array

(static) unique(arr) → {Array}

Source:

Returns an array of unique elements contained in an array.

Parameters:
Name Type Description
arr Array

An array.

Returns:

An array of unique elements contained within the array supplied as an argument.

Type
Array