Module: UWA/Array

UWA/Array

Array utility functions

Index

Methods

<static> UWA.Array.equals(array, compare) → {Boolean}

Test wether two arrays are equal. Deprecated in favor of UWA.equals.

Example
var isEquals = UWA.Array.equals([], []);
// isEquals value is now `true`
var isEquals = UWA.Array.equals([1], [1,2,3]);
// isEquals value is now `false`
Parameters
Name Type Description
array Array

an array or array-like object

compare Array

Array need to compare

Returns

true if Arrays have the sames values else false.

Type
Boolean

<static> UWA.Array.detect(array, iterator, context) → {*}

Find the first value using a test function iterator.

Example
var search = UWA.Array.detect([8, 5, 6, 3, 5], function (v,i) { return v < 5 });
// search value is 3
Parameters
Name Type Description
array Array

an array or array-like object

iterator Function

A function applied to the values of the array The function is called with the context passed as second argument, and the current value, the current index and this array as arguments. When this function return a truthy value, the iteration stops and the current array value is returned.

context Object

Object to use as this

Returns

The first value of the array matching the iterator function, or undefined if none of the values matches.

Type
*

<static> UWA.Array.invoke(array, fn, parametters) → {Array}

Executes a provided method once per array object.

Example
var test = [' foo', '  bar  '];
UWA.Array.invoke(test, 'trim').join(',');
// returns "foo,bar"

UWA.Array.invoke(document.body.getElements('.item'), 'hide');
// hides all .item elements
Parameters
Name Type Description
array Array

an array

fn String

Method to call on every objects

parametters Other

parametters passed to the method call

Returns

The list of the results of method call.

Type
Array

<static> UWA.Array.erase(array, item) → {Array}

Erase every item contained in the array. Original array is modified.

Example
var test = ['red', 'green', 'red'];
UWA.Array.erase(test, 'red'); // returns ['green']
UWA.Array.erase(test, 'purple'); // returns ['red', 'green', 'red']
Parameters
Name Type Description
array Array

an array

item Mixed

An item potentially defined in the array

Returns

The original array modified

Type
Array