Move

Move

Utility class that provides methods to move Array elements into a specific order.

Methods

(static) inOrder(arr, property, valueOrder) → {array}

Source:

Returns a new array with all all array elements moved into the specified order. Elements with identical object property values are moved together i.e retain their original relative order. Any unordered values from the original array are appended to the end of the new array. The original array is unchanged.

Example
// b is [{"prop": "", "val": 1}, {"prop": "2", "val": 4}, {"prop": null, "val": 2}, {"prop": "10", "val": 3}]
const a = [{"prop": "10", "val": 3}, {"prop": "", "val": 1}, {"prop": "2", "val": 4}, {"prop": null, "val": 2}];
const b = Move.inOrder(a, "val", [3, 1, 4, 2]);
Parameters:
Name Type Description
arr array

Array of objects to examine

property string

Object property to use for the reorder.

valueOrder array

Desired order of property values.

Returns:
Type
array

(static) toEnd(arr, predicate) → {array}

Source:

Returns a new array with all the array elements that match the predicate moved to the end of the array. Moved elements are appended in the order in which they appear in the original array. The original array is unchanged.

Example
// b becomes [{"prop": "", "val": 1}, {"prop": "2", "val": 4}, {"prop": null, "val": 2}, {"prop": "10", "val": 3}]
const a = [{"prop": "", "val": 1}, {"prop": null, "val": 2}, {"prop": "10", "val": 3}, {"prop": "2", "val": 4}];
const b = Move.toEnd(a, el => el.val > 1 && el.val < 4);
Parameters:
Name Type Description
arr array

Array to examine

predicate function

Filter method that is called for each element in the array. It should return true if the array element is to be moved.

Returns:
Type
array