Comparing version 1.1.0 to 1.2.0
# CHANGELOG | ||
## 1.2.0 (2015-10-18) | ||
+ Use a faster version of [`.flattenDeep()`](https://github.com/woollybogger/pro-array#Array+flattenDeep) by default ([view](https://github.com/woollybogger/pro-array/commit/048f9fe123803c181f36d0a66b52e37c3365b279)) | ||
+ Implement [`.rnatsort()`](https://github.com/woollybogger/pro-array#Array+rnatsort) ([view](https://github.com/woollybogger/pro-array/commit/0aca5bf4fb376bf0f6ce53fe394da0ac0cd58ed9)) | ||
+ Test with iojs and Node v4 ([view](https://github.com/woollybogger/pro-array/commit/6aacf9f17b0cb1e5c476ee7573cdcf72028850fc)) | ||
+ Implement [`.flatten()`](https://github.com/woollybogger/pro-array#Array+flatten) and [`.flattenDeep()`](https://github.com/woollybogger/pro-array#Array+flattenDeep) ([view](https://github.com/woollybogger/pro-array/commit/a05b01afcc006e71ffac194535fc2c5bd404234f)) | ||
## 1.1.0 (2015-05-09) | ||
+ Implement [`.bsearch()`](https://github.com/woollybogger/pro-array#Array#bsearch) ([view](https://github.com/woollybogger/pro-array/commit/5e30c6027038b4baaef9c9614576a93f0eb71d63)) | ||
+ Implement [`.bsearch()`](https://github.com/woollybogger/pro-array#Array+bsearch) ([view](https://github.com/woollybogger/pro-array/commit/5e30c6027038b4baaef9c9614576a93f0eb71d63)) | ||
+ Switch from using natural-compare-lite to string-natural-compare ([view](https://github.com/woollybogger/pro-array/commit/41f120283b99ac48ef2265f4e5af71b83c6b720d)) | ||
+ Rename the [`.rem()`](https://github.com/woollybogger/pro-array#Array#rem) alias to [`.pull()`](https://github.com/woollybogger/pro-array#Array#pull) ([view](https://github.com/woollybogger/pro-array/commit/330045fd0fd03a49fede1029b013b14303b77770)) | ||
+ Make [`.clear()`](https://github.com/woollybogger/pro-array#Array#clear) return the array ([view](https://github.com/woollybogger/pro-array/commit/b38b9bee57f5569e518bdd6417c3fdb51afe0368)) | ||
+ Optimize [`.chunk()`](https://github.com/woollybogger/pro-array#Array#chunk) ([view](https://github.com/woollybogger/pro-array/commit/cfc17a41fce05b336d97c5a9fd7f7868bc8d7151)) | ||
+ Fix bug in [`.intersect()`](https://github.com/woollybogger/pro-array#Array#intersect) ([view](https://github.com/woollybogger/pro-array/commit/af00b28a9de90d628a618a5b5aec5ba2e370eea9)) | ||
+ Add new [`.xor()`](https://github.com/woollybogger/pro-array#Array#xor) method ([view](https://github.com/woollybogger/pro-array/commit/ac4345387c8e716244e0259a492ad4726556fe8d)) | ||
+ Rename the [`.rem()`](https://github.com/woollybogger/pro-array#Array+rem) alias to [`.pull()`](https://github.com/woollybogger/pro-array#Array+pull) ([view](https://github.com/woollybogger/pro-array/commit/330045fd0fd03a49fede1029b013b14303b77770)) | ||
+ Make [`.clear()`](https://github.com/woollybogger/pro-array#Array+clear) return the array ([view](https://github.com/woollybogger/pro-array/commit/b38b9bee57f5569e518bdd6417c3fdb51afe0368)) | ||
+ Optimize [`.chunk()`](https://github.com/woollybogger/pro-array#Array+chunk) ([view](https://github.com/woollybogger/pro-array/commit/cfc17a41fce05b336d97c5a9fd7f7868bc8d7151)) | ||
+ Fix bug in [`.intersect()`](https://github.com/woollybogger/pro-array#Array+intersect) ([view](https://github.com/woollybogger/pro-array/commit/af00b28a9de90d628a618a5b5aec5ba2e370eea9)) | ||
+ Add new [`.xor()`](https://github.com/woollybogger/pro-array#Array+xor) method ([view](https://github.com/woollybogger/pro-array/commit/ac4345387c8e716244e0259a492ad4726556fe8d)) |
@@ -0,0 +0,0 @@ The MIT License (MIT) |
{ | ||
"name": "pro-array", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Extends the functionality of Arrays with useful methods of unparalleled performance", | ||
@@ -37,14 +37,16 @@ "main": "pro-array.js", | ||
"dependencies": { | ||
"string-natural-compare": "^1.0.0" | ||
"string-natural-compare": "^1.1.1" | ||
}, | ||
"devDependencies": { | ||
"grunt": "~0.4.5", | ||
"grunt-contrib-jshint": "^0.11.2", | ||
"grunt-jscs": "~1.8.0", | ||
"grunt-jsdoc-to-markdown": "~1.1.0", | ||
"grunt-contrib-jshint": "^0.11.3", | ||
"grunt-jscs": "~2.1.0", | ||
"grunt-jsdoc-to-markdown": "~1.1.1", | ||
"grunt-jsonlint": "^1.0.4", | ||
"grunt-mocha-cov": "~0.4.0", | ||
"mocha": "^2.2.4", | ||
"should": "^6.0.1" | ||
"mocha": "^2.3.3", | ||
"should": "^7.1.0", | ||
"should-sinon": "0.0.3", | ||
"sinon": "^1.17.1" | ||
} | ||
} |
155
pro-array.js
/** | ||
* ProArray | ||
* @version 1.1.0 | ||
* @version 1.2.0 | ||
* @copyright 2015 Nathan Woltman | ||
@@ -23,2 +23,40 @@ * @license MIT https://github.com/woollybogger/pro-array/blob/master/LICENSE.txt | ||
function flattenDeepBase(array, result) { | ||
for (var i = 0; i < array.length; i++) { | ||
var value = array[i]; | ||
if (Array.isArray(value)) { | ||
flattenDeepBase(value, result); | ||
} else { | ||
result.push(value); | ||
} | ||
} | ||
return result; | ||
} | ||
function flattenDeepNoCallStack(array) { | ||
var result = []; | ||
var stackPointer = null; | ||
var i = 0; | ||
for (;;) { | ||
if (i < array.length) { | ||
var value = array[i++]; | ||
if (Array.isArray(value)) { | ||
stackPointer = {array: array, index: i, previous: stackPointer}; | ||
array = value; | ||
i = 0; | ||
} else { | ||
result.push(value); | ||
} | ||
} else if (stackPointer) { // Move back up the stack | ||
array = stackPointer.array; | ||
i = stackPointer.index; | ||
stackPointer = stackPointer.previous; | ||
} else { // Done flattening | ||
return result; | ||
} | ||
} | ||
} | ||
function numericalCompare(a, b) { | ||
@@ -32,2 +70,10 @@ return a - b; | ||
function reverseNaturalCompare(a, b) { | ||
return String.naturalCompare(b, a); | ||
} | ||
function reverseNaturalCaseCompare(a, b) { | ||
return String.naturalCaseCompare(b, a); | ||
} | ||
function xorBase(a, b) { | ||
@@ -86,4 +132,7 @@ var result = []; | ||
* | ||
* [1, 2, 3, 4].bsearch(1, function(a, b) { | ||
* return a - b; | ||
* // Search an array of people sorted by age | ||
* var finn = {name: 'Finn', age: 12}; | ||
* var jake = {name: 'Jake', age: 28}; | ||
* [finn, jake].bsearch(finn, function(a, b) { | ||
* return a.age - b.age; | ||
* }); | ||
@@ -296,3 +345,3 @@ * // -> 0 | ||
* new Array(1).each(console.log.bind(console)); | ||
* // -> undefined 0 ['a', 'b', 'c'] | ||
* // -> undefined 0 [undefined] | ||
* // -> [undefined] | ||
@@ -355,2 +404,61 @@ * | ||
/** | ||
* Flattens a nested array. If `isDeep` is true, the array is recursively | ||
* flattened, otherwise it’s only flattened a single level. | ||
* | ||
* @function Array#flatten | ||
* @param {boolean} [isDeep=false] - Specifies a deep flatten. | ||
* @param {boolean} [noCallStack=false] - Specifies if an algorithm that is not susceptible to call stack limits | ||
* should be used, allowing very deeply nested arrays to be flattened. Ignored if `isDeep` is not `true`. | ||
* @returns {Array} The new flattened array. | ||
* | ||
* @example | ||
* [1, [2, 3, [4]]].flatten(); | ||
* // -> [1, 2, 3, [4]] | ||
* | ||
* // using `isDeep` | ||
* [1, [2, 3, [4]]].flatten(true); | ||
* // -> [1, 2, 3, 4] | ||
*/ | ||
flatten: function(isDeep, noCallStack) { | ||
if (isDeep) { | ||
return this.flattenDeep(noCallStack); | ||
} | ||
var result = []; | ||
for (var i = 0; i < this.length; i++) { | ||
var value = this[i]; | ||
if (Array.isArray(value)) { | ||
for (var j = 0; j < value.length; j++) { | ||
result.push(value[j]); | ||
} | ||
} else { | ||
result.push(value); | ||
} | ||
} | ||
return result; | ||
}, | ||
/** | ||
* Recursively flattens a nested array. | ||
* | ||
* @function Array#flattenDeep | ||
* @param {boolean} [noCallStack=false] - Specifies if an algorithm that is not susceptible to call stack limits | ||
* should be used, allowing very deeply nested arrays (i.e. > 9000 levels) to be flattened. | ||
* @returns {Array} The new flattened array. | ||
* | ||
* @example | ||
* [1, [2, 3, [4]]].flattenDeep(); | ||
* // -> [1, 2, 3, 4] | ||
*/ | ||
flattenDeep: function(noCallStack) { | ||
if (noCallStack) { | ||
return flattenDeepNoCallStack(this); | ||
} | ||
return flattenDeepBase(this, []); | ||
}, | ||
/** | ||
* Retrieve an element in the array. | ||
@@ -431,3 +539,3 @@ * | ||
* String.alphabet = 'ABDEFGHIJKLMNOPRSŠZŽTUVÕÄÖÜXYabdefghijklmnoprsšzžtuvõäöüxy'; | ||
* ['t', 'z', 'x', 'õ'].sort(String.naturalCompare); | ||
* ['t', 'z', 'x', 'õ'].natsort(); | ||
* // -> ['z', 't', 'õ', 'x'] | ||
@@ -454,2 +562,22 @@ * ``` | ||
/** | ||
* Sorts an array in place using a natural string comparison algorithm and returns the array. | ||
* | ||
* The same as {@link Array#natsort|`.natsort()`} except the strings are sorted in descending order. | ||
* | ||
* @function Array#rnatsort | ||
* @param {boolean} [caseInsensitive=false] - Set this to `true` to ignore letter casing when sorting. | ||
* @returns {Array} The array this method was called on. | ||
* | ||
* @example | ||
* var files = ['a.txt', 'a10.txt', 'a2.txt', 'a1.txt']; | ||
* files.rnatsort(); | ||
* console.log(files); | ||
* // -> ['a.txt', 'a1.txt', 'a2.txt', 'a10.txt'] | ||
* // -> ['a10.txt', 'a2.txt', 'a1.txt', 'a.txt'] | ||
*/ | ||
rnatsort: function(caseInsensitive) { | ||
return this.sort(caseInsensitive ? reverseNaturalCaseCompare : reverseNaturalCompare); | ||
}, | ||
/** | ||
* Sorts an array in place using a numerical comparison algorithm | ||
@@ -462,5 +590,5 @@ * (sorts numbers from lowest to highest) and returns the array. | ||
* @example | ||
* var files = [10, 0, 2, 1]; | ||
* files.numsort(); | ||
* console.log(files); | ||
* var a = [10, 0, 2, 1]; | ||
* a.numsort(); | ||
* console.log(a); | ||
* // -> [0, 1, 2, 3] | ||
@@ -480,5 +608,5 @@ */ | ||
* @example | ||
* var files = [10, 0, 2, 1]; | ||
* files.rnumsort(); | ||
* console.log(files); | ||
* var a = [10, 0, 2, 1]; | ||
* a.rnumsort(); | ||
* console.log(a); | ||
* // -> [3, 2, 1, 0] | ||
@@ -665,3 +793,2 @@ */ | ||
* // -> [1, 4, 5] | ||
* | ||
* // Explanation: | ||
@@ -684,3 +811,3 @@ * // [1, 2, 5] ⊕ [2, 3, 5] ⊕ [3, 4, 5] = [1, 4, 5] | ||
return result; | ||
} | ||
}, | ||
}; | ||
@@ -693,3 +820,3 @@ | ||
configurable: true, | ||
writable: true | ||
writable: true, | ||
}; | ||
@@ -696,0 +823,0 @@ } |
201
README.md
@@ -36,24 +36,27 @@ # ProArray | ||
* [Array](#Array) | ||
* [.bsearch(value, [compareFunction])](#Array#bsearch) ⇒ <code>number</code> | ||
* [.chunk([size])](#Array#chunk) ⇒ <code>[Array](#Array)</code> | ||
* [.clear()](#Array#clear) ⇒ <code>[Array](#Array)</code> | ||
* [.clone()](#Array#clone) ⇒ <code>[Array](#Array)</code> | ||
* [.compact()](#Array#compact) ⇒ <code>[Array](#Array)</code> | ||
* [.diff()](#Array#diff) | ||
* [.difference(...*arrays)](#Array#difference) ⇒ <code>[Array](#Array)</code> | ||
* [.each(callback, [safeIteration])](#Array#each) ⇒ <code>[Array](#Array)</code> | ||
* [~eachCallback](#Array#each..eachCallback) : <code>function</code> | ||
* [.equals(array)](#Array#equals) ⇒ <code>boolean</code> | ||
* [.get(index)](#Array#get) ⇒ <code>\*</code> | ||
* [.intersect(...*arrays)](#Array#intersect) ⇒ <code>[Array](#Array)</code> | ||
* [.natsort([caseInsensitive])](#Array#natsort) ⇒ <code>[Array](#Array)</code> | ||
* [.numsort()](#Array#numsort) ⇒ <code>[Array](#Array)</code> | ||
* [.pull()](#Array#pull) | ||
* [.remove(...*items)](#Array#remove) ⇒ <code>[Array](#Array)</code> | ||
* [.rnumsort()](#Array#rnumsort) ⇒ <code>[Array](#Array)</code> | ||
* [.union(...*arrays)](#Array#union) ⇒ <code>[Array](#Array)</code> | ||
* [.uniq()](#Array#uniq) | ||
* [.unique([isSorted])](#Array#unique) ⇒ <code>[Array](#Array)</code> | ||
* [.without(...*items)](#Array#without) ⇒ <code>[Array](#Array)</code> | ||
* [.xor(...*arrays)](#Array#xor) ⇒ <code>[Array](#Array)</code> | ||
* [.bsearch(value, [compareFunction])](#Array+bsearch) ⇒ <code>number</code> | ||
* [.chunk([size])](#Array+chunk) ⇒ <code>[Array](#Array)</code> | ||
* [.clear()](#Array+clear) ⇒ <code>[Array](#Array)</code> | ||
* [.clone()](#Array+clone) ⇒ <code>[Array](#Array)</code> | ||
* [.compact()](#Array+compact) ⇒ <code>[Array](#Array)</code> | ||
* [.diff()](#Array+diff) | ||
* [.difference(...*arrays)](#Array+difference) ⇒ <code>[Array](#Array)</code> | ||
* [.each(callback, [safeIteration])](#Array+each) ⇒ <code>[Array](#Array)</code> | ||
* [~eachCallback](#Array+each..eachCallback) : <code>function</code> | ||
* [.equals(array)](#Array+equals) ⇒ <code>boolean</code> | ||
* [.flatten([isDeep], [noCallStack])](#Array+flatten) ⇒ <code>[Array](#Array)</code> | ||
* [.flattenDeep([noCallStack])](#Array+flattenDeep) ⇒ <code>[Array](#Array)</code> | ||
* [.get(index)](#Array+get) ⇒ <code>\*</code> | ||
* [.intersect(...*arrays)](#Array+intersect) ⇒ <code>[Array](#Array)</code> | ||
* [.natsort([caseInsensitive])](#Array+natsort) ⇒ <code>[Array](#Array)</code> | ||
* [.numsort()](#Array+numsort) ⇒ <code>[Array](#Array)</code> | ||
* [.pull()](#Array+pull) | ||
* [.remove(...*items)](#Array+remove) ⇒ <code>[Array](#Array)</code> | ||
* [.rnatsort([caseInsensitive])](#Array+rnatsort) ⇒ <code>[Array](#Array)</code> | ||
* [.rnumsort()](#Array+rnumsort) ⇒ <code>[Array](#Array)</code> | ||
* [.union(...*arrays)](#Array+union) ⇒ <code>[Array](#Array)</code> | ||
* [.uniq()](#Array+uniq) | ||
* [.unique([isSorted])](#Array+unique) ⇒ <code>[Array](#Array)</code> | ||
* [.without(...*items)](#Array+without) ⇒ <code>[Array](#Array)</code> | ||
* [.xor(...*arrays)](#Array+xor) ⇒ <code>[Array](#Array)</code> | ||
@@ -63,3 +66,3 @@ | ||
<a name="Array#bsearch"></a> | ||
<a name="Array+bsearch"></a> | ||
### array.bsearch(value, [compareFunction]) ⇒ <code>number</code> | ||
@@ -92,4 +95,7 @@ Finds the index of a value in a sorted array using a binary search algorithm. | ||
[1, 2, 3, 4].bsearch(1, function(a, b) { | ||
return a - b; | ||
// Search an array of people sorted by age | ||
var finn = {name: 'Finn', age: 12}; | ||
var jake = {name: 'Jake', age: 28}; | ||
[finn, jake].bsearch(finn, function(a, b) { | ||
return a.age - b.age; | ||
}); | ||
@@ -106,3 +112,3 @@ // -> 0 | ||
<a name="Array#chunk"></a> | ||
<a name="Array+chunk"></a> | ||
### array.chunk([size]) ⇒ <code>[Array](#Array)</code> | ||
@@ -134,3 +140,3 @@ Creates an array of elements split into groups the length of `size`. If the array | ||
<a name="Array#clear"></a> | ||
<a name="Array+clear"></a> | ||
### array.clear() ⇒ <code>[Array](#Array)</code> | ||
@@ -151,3 +157,3 @@ Removes all elements from the array. | ||
<a name="Array#clone"></a> | ||
<a name="Array+clone"></a> | ||
### array.clone() ⇒ <code>[Array](#Array)</code> | ||
@@ -168,3 +174,3 @@ Creates a shallow copy of the array. | ||
<a name="Array#compact"></a> | ||
<a name="Array+compact"></a> | ||
### array.compact() ⇒ <code>[Array](#Array)</code> | ||
@@ -184,11 +190,11 @@ Returns a new array with all falsey values removed. Falsey values | ||
<a name="Array#diff"></a> | ||
<a name="Array+diff"></a> | ||
### array.diff() | ||
Alias of [difference](#Array#difference). | ||
Alias of [difference](#Array+difference). | ||
**See**: [difference](#Array#difference) | ||
**See**: [difference](#Array+difference) | ||
--- | ||
<a name="Array#difference"></a> | ||
<a name="Array+difference"></a> | ||
### array.difference(...*arrays) ⇒ <code>[Array](#Array)</code> | ||
@@ -213,3 +219,3 @@ Returns a new array with all of the values of the array that are not in | ||
<a name="Array#each"></a> | ||
<a name="Array+each"></a> | ||
### array.each(callback, [safeIteration]) ⇒ <code>[Array](#Array)</code> | ||
@@ -228,3 +234,3 @@ Invokes a callback function on each element in the array. | ||
| --- | --- | --- | --- | | ||
| callback | <code>[eachCallback](#Array#each..eachCallback)</code> | | A function to be executed on each element in the array. | | ||
| callback | <code>[eachCallback](#Array+each..eachCallback)</code> | | A function to be executed on each element in the array. | | ||
| [safeIteration] | <code>boolean</code> | <code>false</code> | When `true`, the callback will not be invoked for indexes that have been deleted or elided (are undefined). | | ||
@@ -254,3 +260,3 @@ | ||
new Array(1).each(console.log.bind(console)); | ||
// -> undefined 0 ['a', 'b', 'c'] | ||
// -> undefined 0 [undefined] | ||
// -> [undefined] | ||
@@ -264,3 +270,3 @@ | ||
<a name="Array#each..eachCallback"></a> | ||
<a name="Array+each..eachCallback"></a> | ||
#### each~eachCallback : <code>function</code> | ||
@@ -272,3 +278,3 @@ | ||
| index | <code>number</code> | The index of the current element being processed. | | ||
| array | <code>[Array](#Array)</code> | The array [`.each()`](#Array#each) was called on. | | ||
| array | <code>[Array](#Array)</code> | The array [`.each()`](#Array+each) was called on. | | ||
@@ -278,3 +284,3 @@ | ||
<a name="Array#equals"></a> | ||
<a name="Array+equals"></a> | ||
### array.equals(array) ⇒ <code>boolean</code> | ||
@@ -309,3 +315,47 @@ Determines if the arrays are equal by doing a shallow comparison of their elements using strict equality. | ||
<a name="Array#get"></a> | ||
<a name="Array+flatten"></a> | ||
### array.flatten([isDeep], [noCallStack]) ⇒ <code>[Array](#Array)</code> | ||
Flattens a nested array. If `isDeep` is true, the array is recursively | ||
flattened, otherwise it’s only flattened a single level. | ||
| Param | Type | Default | Description | | ||
| --- | --- | --- | --- | | ||
| [isDeep] | <code>boolean</code> | <code>false</code> | Specifies a deep flatten. | | ||
| [noCallStack] | <code>boolean</code> | <code>false</code> | Specifies if an algorithm that is not susceptible to call stack limits should be used, allowing very deeply nested arrays to be flattened. Ignored if `isDeep` is not `true`. | | ||
**Returns**: <code>[Array](#Array)</code> - The new flattened array. | ||
**Example** | ||
```js | ||
[1, [2, 3, [4]]].flatten(); | ||
// -> [1, 2, 3, [4]] | ||
// using `isDeep` | ||
[1, [2, 3, [4]]].flatten(true); | ||
// -> [1, 2, 3, 4] | ||
``` | ||
--- | ||
<a name="Array+flattenDeep"></a> | ||
### array.flattenDeep([noCallStack]) ⇒ <code>[Array](#Array)</code> | ||
Recursively flattens a nested array. | ||
| Param | Type | Default | Description | | ||
| --- | --- | --- | --- | | ||
| [noCallStack] | <code>boolean</code> | <code>false</code> | Specifies if an algorithm that is not susceptible to call stack limits should be used, allowing very deeply nested arrays (i.e. > 9000 levels) to be flattened. | | ||
**Returns**: <code>[Array](#Array)</code> - The new flattened array. | ||
**Example** | ||
```js | ||
[1, [2, 3, [4]]].flattenDeep(); | ||
// -> [1, 2, 3, 4] | ||
``` | ||
--- | ||
<a name="Array+get"></a> | ||
### array.get(index) ⇒ <code>\*</code> | ||
@@ -343,3 +393,3 @@ Retrieve an element in the array. | ||
<a name="Array#intersect"></a> | ||
<a name="Array+intersect"></a> | ||
### array.intersect(...*arrays) ⇒ <code>[Array](#Array)</code> | ||
@@ -367,3 +417,3 @@ Returns an new array that is the [set intersection](http://en.wikipedia.org/wiki/Intersection_(set_theory)) | ||
<a name="Array#natsort"></a> | ||
<a name="Array+natsort"></a> | ||
### array.natsort([caseInsensitive]) ⇒ <code>[Array](#Array)</code> | ||
@@ -377,3 +427,3 @@ Sorts an array in place using a natural string comparison algorithm and returns the array. | ||
String.alphabet = 'ABDEFGHIJKLMNOPRSŠZŽTUVÕÄÖÜXYabdefghijklmnoprsšzžtuvõäöüxy'; | ||
['t', 'z', 'x', 'õ'].sort(String.naturalCompare); | ||
['t', 'z', 'x', 'õ'].natsort(); | ||
// -> ['z', 't', 'õ', 'x'] | ||
@@ -402,3 +452,3 @@ ``` | ||
<a name="Array#numsort"></a> | ||
<a name="Array+numsort"></a> | ||
### array.numsort() ⇒ <code>[Array](#Array)</code> | ||
@@ -412,5 +462,5 @@ Sorts an array in place using a numerical comparison algorithm | ||
```js | ||
var files = [10, 0, 2, 1]; | ||
files.numsort(); | ||
console.log(files); | ||
var a = [10, 0, 2, 1]; | ||
a.numsort(); | ||
console.log(a); | ||
// -> [0, 1, 2, 3] | ||
@@ -421,15 +471,15 @@ ``` | ||
<a name="Array#pull"></a> | ||
<a name="Array+pull"></a> | ||
### array.pull() | ||
Alias of [remove](#Array#remove). | ||
Alias of [remove](#Array+remove). | ||
**See**: [remove](#Array#remove) | ||
**See**: [remove](#Array+remove) | ||
--- | ||
<a name="Array#remove"></a> | ||
<a name="Array+remove"></a> | ||
### array.remove(...*items) ⇒ <code>[Array](#Array)</code> | ||
Removes all occurrences of the passed in items from the array and returns the array. | ||
__Note:__ Unlike [`.without()`](#Array#without), this method mutates the array. | ||
__Note:__ Unlike [`.without()`](#Array+without), this method mutates the array. | ||
@@ -459,3 +509,27 @@ | ||
<a name="Array#rnumsort"></a> | ||
<a name="Array+rnatsort"></a> | ||
### array.rnatsort([caseInsensitive]) ⇒ <code>[Array](#Array)</code> | ||
Sorts an array in place using a natural string comparison algorithm and returns the array. | ||
The same as [`.natsort()`](#Array+natsort) except the strings are sorted in descending order. | ||
| Param | Type | Default | Description | | ||
| --- | --- | --- | --- | | ||
| [caseInsensitive] | <code>boolean</code> | <code>false</code> | Set this to `true` to ignore letter casing when sorting. | | ||
**Returns**: <code>[Array](#Array)</code> - The array this method was called on. | ||
**Example** | ||
```js | ||
var files = ['a.txt', 'a10.txt', 'a2.txt', 'a1.txt']; | ||
files.rnatsort(); | ||
console.log(files); | ||
// -> ['a.txt', 'a1.txt', 'a2.txt', 'a10.txt'] | ||
// -> ['a10.txt', 'a2.txt', 'a1.txt', 'a.txt'] | ||
``` | ||
--- | ||
<a name="Array+rnumsort"></a> | ||
### array.rnumsort() ⇒ <code>[Array](#Array)</code> | ||
@@ -469,5 +543,5 @@ Sorts an array in place using a reverse numerical comparison algorithm | ||
```js | ||
var files = [10, 0, 2, 1]; | ||
files.rnumsort(); | ||
console.log(files); | ||
var a = [10, 0, 2, 1]; | ||
a.rnumsort(); | ||
console.log(a); | ||
// -> [3, 2, 1, 0] | ||
@@ -478,3 +552,3 @@ ``` | ||
<a name="Array#union"></a> | ||
<a name="Array+union"></a> | ||
### array.union(...*arrays) ⇒ <code>[Array](#Array)</code> | ||
@@ -502,11 +576,11 @@ Returns an array that is the [union](http://en.wikipedia.org/wiki/Union_%28set_theory%29) | ||
<a name="Array#uniq"></a> | ||
<a name="Array+uniq"></a> | ||
### array.uniq() | ||
Alias of [unique](#Array#unique). | ||
Alias of [unique](#Array+unique). | ||
**See**: [unique](#Array#unique) | ||
**See**: [unique](#Array+unique) | ||
--- | ||
<a name="Array#unique"></a> | ||
<a name="Array+unique"></a> | ||
### array.unique([isSorted]) ⇒ <code>[Array](#Array)</code> | ||
@@ -538,3 +612,3 @@ Returns a duplicate-free clone of the array. | ||
<a name="Array#without"></a> | ||
<a name="Array+without"></a> | ||
### array.without(...*items) ⇒ <code>[Array](#Array)</code> | ||
@@ -561,3 +635,3 @@ Returns a copy of the array without any elements from the input parameters. | ||
<a name="Array#xor"></a> | ||
<a name="Array+xor"></a> | ||
### array.xor(...*arrays) ⇒ <code>[Array](#Array)</code> | ||
@@ -581,3 +655,2 @@ Finds the [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference) | ||
// -> [1, 4, 5] | ||
// Explanation: | ||
@@ -584,0 +657,0 @@ // [1, 2, 5] ⊕ [2, 3, 5] ⊕ [3, 4, 5] = [1, 4, 5] |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46165
752
645
10