new Array()
Native array prototype.
- Source:
Methods
-
distinct() → {Array}
-
Filter a list to contain only unique values.
- Source:
- To Do:
-
- Use [].filter(). As it iterates the array, items can be excluded if they match (strict, ===) any previous indexes. May or may not be more efficient, but would provide finer matching control than a plain indexOf lookup.
Returns:
List of unique values.
- Type
- Array
-
elementAttributeSort(properties, order) → {Array}
-
Sort a list of elements by attribute(s).
Parameters:
Name Type Argument Default Description properties
String Properties of each object to compare.
order
Number <optional>
1 Positive for ascending, negative for descending.
- Source:
- See:
- To Do:
-
- Concatenating won't work with property values of different lengths: foo.a = 'ab'; foo.b = 'z'; bar.a = 'abc'; bar.b = 'y'; foo's a + b -> 'abz' bar's a + b -> 'abcy' ...foo will sort after bar though that's not what we want. Either: - Calculate the longest value (.toString() if it's not) length and right-pad them all with the appropriate number of spaces to make them equal. - (Faster) enforce the primary sort first because in most cases a sub-comparison isn't necessary. Also use a schwartzian transform to cache values, preventing accesses for every comparison. Will have varying speed improvements depending on which comparison method the runtime uses, some make vastly more comparisons.
Returns:
Sorted list.
- Type
- Array
-
keySort(property, order) → {Array}
-
Sort a list of objects by a specific property.
Parameters:
Name Type Argument Default Description property
String Value of each object to compare.
order
Number <optional>
1 Positive for ascending, negative for descending.
- Source:
- See:
- To Do:
-
- Use a schwartzian transform to cache values, preventing accesses for every comparison. Will have varying speed improvements depending on which comparison method the runtime uses, some make vastly more comparisons.
Returns:
Sorted list.
- Type
- Array
-
njoin(separator) → {String}
-
Array#join, skipping falsy values.
Parameters:
Name Type Description separator
String Characters to use as delimiters.
- Source:
- To Do:
-
- This will exclude ANY falsy values, e.g. '' or 0, not just null as originally described. Is this desired? Also use [].filter() to exclude, followed by a native join.
Returns:
Delimited string.
- Type
- String
Example
['a', '', 'c'].njoin(', ') -> 'a, c'
-
njoin(separator, callback) → {Array}
-
Array#split, skipping resulting empty strings.
Parameters:
Name Type Description separator
String Characters to detect as delimiters.
callback
function Function to process indexes.
- Source:
- To Do:
-
- Use native filter after native split. Also callback functionality can be accomplished with filter on the returned array and needn't be duplicated here.
Returns:
Resulting strings.
- Type
- Array
Example
'a, , c'.nsplit(', ') -> ['a', 'c']
-
pluck(prop) → {Array}
-
Queries an array of objects for a specific property and returns a list of those values.
Parameters:
Name Type Description prop
String Name of property value to retrieve from each object.
Returns:
List of property values.
- Type
- Array
-
pushEach(other) → {Number}
-
Concatenates this list with another.
Parameters:
Name Type Description other
Array List to concatenate to this one.
- Source:
- To Do:
-
- It would be more useful to return this (the array we're operating on) because the method could be chained. Length is easy to grab at any time. This method would be no different than native [...].concat([...]).
Returns:
Count of all values.
- Type
- Number