necessary 11.3.0 → 11.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -32
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -600,7 +600,7 @@ pathWithoutTopmostDirectoryNameFromPath("root/etc/init.conf"); // returns 'etc/i
|
|
|
600
600
|
- `find()`
|
|
601
601
|
- `prune()`
|
|
602
602
|
- `patch()`
|
|
603
|
-
- `
|
|
603
|
+
- `compress()`
|
|
604
604
|
- `augment()`
|
|
605
605
|
- `separate()`
|
|
606
606
|
- `forwardsFind()`
|
|
@@ -634,7 +634,6 @@ concat([1, 2, 3], 4); // the array argument becomes [1, 2, 3, 4]
|
|
|
634
634
|
|
|
635
635
|
```
|
|
636
636
|
clear([1, 2, 3]); // the array argument becomes []
|
|
637
|
-
// returnsll be [1, 2, 3]
|
|
638
637
|
```
|
|
639
638
|
|
|
640
639
|
* The `copy()` function copies the second array argument over the top of the first array argument, in other words it replaces each element of the first array argument with the corresponding element in the second array argument. If there are more elements in the second array argument that the first, the first is lengthened:
|
|
@@ -652,74 +651,55 @@ merge([1, 2, 3], [4, 5, 6, 7]); // the first array argument becomes [1, 2, 3, 4,
|
|
|
652
651
|
* The `splice()` function works in a similar vein to its native counterpart, however it takes an array as the optional fourth argument rather than a series of elements from the fourth argument onwards. It mutates the first array argument and returns an array of the elements that have been removed from it:
|
|
653
652
|
|
|
654
653
|
```
|
|
655
|
-
splice([1, 2, 3], 1, 2, [4, 5]); //
|
|
656
|
-
// the first array argument becomes [1, 4, 5]
|
|
654
|
+
splice([1, 2, 3], 1, 2, [4, 5]); // the first array argument becomes [1, 4, 5]
|
|
657
655
|
```
|
|
658
656
|
|
|
659
657
|
* The `replace()` function will replace an element in the array with the given element the first time that the callback function returns a truthy value:
|
|
660
658
|
|
|
661
659
|
```
|
|
662
|
-
replace([1,
|
|
663
|
-
return element === 0;
|
|
664
|
-
}); // the first array argument becomes [1, 2, 3, -1, -2]
|
|
660
|
+
replace([1, 0, -2], 3, (element, index) => (element === 0)); // the array argument becomes [1, 3, -2]
|
|
665
661
|
```
|
|
666
662
|
|
|
667
663
|
* The `filter()` function is like its native counterpart, however it filters the first array argument *in place*. The second argument should be a callback function that will be invoked for each element of the array. If it does not return a truthy value, the corresponding element will be removed.
|
|
668
664
|
|
|
669
665
|
```
|
|
670
|
-
filter([1, 2, -
|
|
671
|
-
return element > 0;
|
|
672
|
-
}); // the first array argument becomes [1, 2]
|
|
673
|
-
// returns [-1, -2]
|
|
666
|
+
filter([1, 2, -2], (element, index) => (element > 0)); // the array argument becomes [1, 2]
|
|
674
667
|
```
|
|
675
668
|
|
|
676
669
|
* The `find()` function is like its native counterpart, however it returns an array of all the elements for which the callback function returns a truthy value, rather than just the first:
|
|
677
670
|
|
|
678
671
|
```
|
|
679
|
-
find([1, 2, -1, -2], (element, index) =>
|
|
680
|
-
return element > 0;
|
|
681
|
-
}); // returnsll be [1, 2]
|
|
672
|
+
find([1, 2, -1, -2], (element, index) => (element > 0)); // returns [1, 2]
|
|
682
673
|
```
|
|
683
674
|
|
|
684
675
|
* The `prune()` function is much like the `filter()` function, however it will terminate the first time that the callback function does not return a truthy value:
|
|
685
676
|
|
|
686
677
|
```
|
|
687
|
-
prune([1, 2, -1, -2], (element, index) =>
|
|
688
|
-
return element > 0;
|
|
689
|
-
}); // the first array argument becomes [1, 2, -2]
|
|
690
|
-
// returns -1
|
|
678
|
+
prune([1, 2, -1, -2], (element, index) => (element > 0)); // the array argument becomes [1, 2]
|
|
691
679
|
```
|
|
692
680
|
|
|
693
|
-
* The `patch()` function will append the given element to the
|
|
681
|
+
* The `patch()` function will append the given element to the array argument the first time that the callback function returns a truthy value:
|
|
694
682
|
|
|
695
683
|
```
|
|
696
|
-
patch([1, 2, 0, -1, -2], 4, (element, index) =>
|
|
697
|
-
return element === 0;
|
|
698
|
-
}); // the first array argument becomes [1, 2, 0, -1, -2, 4]
|
|
684
|
+
patch([1, 2, 0, -1, -2], 4, (element, index) => (element === 0)); // the array argument becomes [1, 2, 0, -1, -2, 4]
|
|
699
685
|
```
|
|
700
686
|
|
|
701
|
-
* The `compress()` function will remove elements from the
|
|
687
|
+
* The `compress()` function will remove elements from the array argument whenever the callback function returns a truthy value:
|
|
702
688
|
|
|
703
689
|
```
|
|
704
|
-
compress([1, 2, 1], (element1, element2) =>
|
|
705
|
-
return element1 === element2;
|
|
706
|
-
}); // the first array argument becomes [1, 2]
|
|
690
|
+
compress([1, 2, 1], (element1, element2) => (element1 === element2)); // the array argument becomes [1, 2]
|
|
707
691
|
```
|
|
708
692
|
|
|
709
693
|
* The `augment()` function appends each of the elements of the second array argument to the first array argument whenever the callback returns a truthy value:
|
|
710
694
|
|
|
711
695
|
```
|
|
712
|
-
augment([1, 2, 3], [-1, 4, -2, 5], (element, index) =>
|
|
713
|
-
return element > 0;
|
|
714
|
-
}); // the first array argument becomes [1, 2, 3, 4, 5]
|
|
696
|
+
augment([1, 2, 3], [-1, 4, -2, 5], (element, index) => (element > 0)); // the array argument becomes [1, 2, 3, 4, 5]
|
|
715
697
|
```
|
|
716
698
|
|
|
717
699
|
* The `separate()` function separates the first array argument, pushing each of its elements onto either the second or the third array argument depending on whether or not the callback returns a truthy value:
|
|
718
700
|
|
|
719
701
|
```
|
|
720
|
-
separate([1, -1, -2, 2, 3, -3], [], [], (element, index) => {
|
|
721
|
-
return element > 0;
|
|
722
|
-
}); // the second and third array arguments become [1, 2, 3] and [-1, -2, 3], respectively.
|
|
702
|
+
separate([1, -1, -2, 2, 3, -3], [], [], (element, index) => {(element > 0)); // the second and third array arguments become [1, 2, 3] and [-1, -2, 3], respectively.
|
|
723
703
|
```
|
|
724
704
|
|
|
725
705
|
The `forwardsXXX()` and `backwardsXXX()`functions do as their names suggest. The `fowardsXXX()` function take an array for their first argument but otherwise behave identically to their native counterparts. The `backwardsXXX()` functions behave similarly, only backwards.
|