Skip to content

Commit 163a328

Browse files
authored
Merge pull request #5 from georapbox/issue-#4
fixes #4
2 parents 4872c9e + ad9dfa8 commit 163a328

File tree

9 files changed

+36
-20
lines changed

9 files changed

+36
-20
lines changed

CHAGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## v1.0.3
4+
5+
- Fixes issue #4. Do not copy array unnecessarily in `del` method if index is a negative number.
6+
37
## v1.0.2
48

59
- Use the array spread operator in delete method.

README.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ import push from 'immutable-arrays/src/immutable-push';
8989
<dd><p>Deletes an element from an array by its index in the array.</p></dd>
9090
</dl>
9191

92-
<a name="immutableArrays.push"></a>
92+
<a id="immutableArrays.push" name="immutableArrays.push"></a>
9393

9494
## immutableArrays.push(array, ...elementN) ⇒ <code>Array</code>
9595
Adds one or more elements to the end of an array by returning
@@ -110,7 +110,7 @@ const resultArray = immutableArrays.push(originalArray, 'f', 'g');
110110
// -> resultArray ['a', 'b', 'c', 'd', 'e', 'f', 'g']
111111
```
112112

113-
<a name="immutableArrays.pop"></a>
113+
<a id="immutableArrays.pop" name="immutableArrays.pop"></a>
114114

115115
## immutableArrays.pop(array) ⇒ <code>Array</code>
116116
Removes the last element from an array by returning
@@ -130,7 +130,7 @@ const resultArray = immutableArrays.pop(originalArray);
130130
// -> resultArray ['a', 'b', 'c', 'd']
131131
```
132132

133-
<a name="immutableArrays.shift"></a>
133+
<a id="immutableArrays.shift" name="immutableArrays.shift"></a>
134134

135135
## immutableArrays.shift(array) ⇒ <code>Array</code>
136136
Removes the first element from an array.
@@ -149,7 +149,7 @@ const resultArray = immutableArrays.shift(originalArray);
149149
// -> resultArray ['b', 'c', 'd', 'e']
150150
```
151151

152-
<a name="immutableArrays.unshift"></a>
152+
<a id="immutableArrays.unshift" name="immutableArrays.unshift"></a>
153153

154154
## immutableArrays.unshift(array, ...elementN) ⇒ <code>Array</code>
155155
Adds one or more elements to the beginning of an array.
@@ -169,7 +169,7 @@ const resultArray = immutableArrays.unshift(originalArray, 'f', 'g');
169169
// -> resultArray ['f', 'g', 'a', 'b', 'c', 'd', 'e']
170170
```
171171

172-
<a name="immutableArrays.reverse"></a>
172+
<a id="immutableArrays.reverse" name="immutableArrays.reverse"></a>
173173

174174
## immutableArrays.reverse(array) ⇒ <code>Array</code>
175175
Reverses an array (not in place).
@@ -189,7 +189,7 @@ const resultArray = immutableArrays.reverse(originalArray);
189189
// -> resultArray ['e', 'd', 'c', 'b', 'a']
190190
```
191191

192-
<a name="immutableArrays.sort"></a>
192+
<a id="immutableArrays.sort" name="immutableArrays.sort"></a>
193193

194194
## immutableArrays.sort(array, [compareFunction]) ⇒ <code>Array</code>
195195
Sorts the elements of an array (not in place) and returns a sorted array.
@@ -223,7 +223,7 @@ const resultArray = immutableArrays.sort(stringArray, (a, b) => a.toLowerCase()
223223
// -> resultArray ['Humpback', 'Blue', 'Beluga']
224224
```
225225

226-
<a name="immutableArrays.splice"></a>
226+
<a id="immutableArrays.splice" name="immutableArrays.splice"></a>
227227

228228
## immutableArrays.splice(array, [start], [deleteCount], [...elementN]) ⇒ <code>Array</code>
229229
Removes existing elements and/or adds new elements to an array.
@@ -285,7 +285,7 @@ const resultArray = immutableArrays.splice(originalArray, originalArray.length -
285285
// -> resultArray ['a', 'b', 'c', 'lorem', 'ipsum']
286286
```
287287

288-
<a name="immutableArrays.del"></a>
288+
<a id="immutableArrays.del" name="immutableArrays.del"></a>
289289

290290
## immutableArrays.del(array, index) ⇒ <code>Array</code>
291291
Deletes an element from an array by its index in the array.
@@ -295,14 +295,18 @@ Deletes an element from an array by its index in the array.
295295
| Param | Type | Description |
296296
| --- | --- | --- |
297297
| array | <code>Array</code> | The original array. |
298-
| index | <code>Number</code> | The index of the element to delete in the original array. |
298+
| index | <code>Number</code> | The index of the element to delete in the original array. If index is a negative number, the original array is returned. |
299299

300300
**Example**
301301
```js
302302
const originalArray = ['a', 'b', 'c', 'd', 'e'];
303303
const resultArray = immutableArrays.del(originalArray, 2);
304304
// -> originalArray ['a', 'b', 'c', 'd', 'e']
305305
// -> resultArray ['a', 'b', 'd', 'e']
306+
307+
const resultArray2 = immutableDelete(originalArray, -1);
308+
// -> originalArray ['a', 'b', 'c', 'd', 'e']
309+
// -> resultArray2 ['a', 'b', 'c', 'd', 'e']
306310
```
307311

308312
## Test

lib/immutableArrays.js

Lines changed: 7 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)