Skip to content

Commit 7093c4a

Browse files
author
DESKTOP-CLP1LAB\detky
committed
- Readme update
- Function "Take" parameters order changed for better usability
1 parent 83f4ada commit 7093c4a

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

PowerArray.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,8 @@ mainContainer.pa.prototypedFunctions_Array = {
12451245

12461246
}
12471247
},
1248-
Take: function (skip, count) {
1248+
Take: function (count, skip) {
1249+
skip = skip || 0;
12491250
var i = 0 + skip, l = this.length, result = [], added = 0;
12501251
for (; i < l && added < count; i++) {
12511252
result.push(this[i]);

README.md

+18-20
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,37 @@
11
# PowerArray
2-
Working with Arrays in Javascript requires manual iteration, is error-prone, difficult to read, repetitive and time-consuming.
2+
Working with Arrays in Javascript requires manual iteration, is error-prone, difficult to read, repetitive and time-consuming. PowerArray simplifies almost everything that has to do with that bads.
33

4-
**What can PowerArray do for you?**
5-
6-
To see it by yourself, please check how many time you need to find out what is doing this code:
4+
## Simple example
5+
The following example filters an array, sort the results and iterates the first 10 matches. It uses the **Where**, **Sort**, **Take** and **RunEach** PowerArray functions.
76

7+
>Given an array of objects (representing persons), called 'peopleArray'
88
```javascript
9-
// Given an Array of objects representing persons, called 'peopleArray'
9+
// With PowerArray:
1010
peopleArray
11-
.Where({ age: Between(18,70), gender: 'M'})
12-
.Sort({ lastName: Sort.AscendingIgnoringCase})
13-
.RunEach(function(item, i) {
14-
console.debug(i + ' ' + item.name); //do something
15-
});
16-
```
17-
18-
And how long for this one?
11+
.Where({ age: Between(18,70), gender: 'M' }) // filter
12+
.Sort{ lastName: Sort.AscendingIgnoringCase }) // sort
13+
.Take(10)
14+
.RunEach(function(item, i) { console.debug(i + ' ' + item.name); } ); // do stuff
1915

20-
```javascript
21-
// Given an Array of objects representing persons, called 'peopleArray'
16+
// In plain Javascript
2217
var result = [], i = 0, l, item;
2318
for(l = peopleArray.length; i < l; i++) {
2419
item = peopleArray[i];
25-
if(item.age > 18 && item.age < 70 && item.gender === 'M') {
20+
if(item.age > 18 && item.age < 70 && item.gender === 'M') { // filtering
2621
result.push(item);
2722
}
2823
}
24+
2925
result.sort(function (a, b) {
30-
return a.lastName.toLowerCase().localeCompare(b.lastName.toLowerCase());
26+
return a.lastName.toLowerCase().localeCompare(b.lastName.toLowerCase()); // sorting
3127
});
32-
for(i = 0, l = result.length; i < l; i++) {
33-
console.debug(i + ' ' + result[i].name); //do something
28+
29+
for(i = 0, l = result.length; i < l && i < 10; i++) {
30+
console.debug(i + ' ' + result[i].name); // do stuff
3431
}
3532
```
3633

37-
**Both codes do exactly the same**, but the first is (at least for me), much easier to understand. It uses the **Where**, **Sort** and **RunEach** PowerArray methods.
34+
**Both codes do exactly the same**, but the first is (at least for me), much easier to understand. Power array adds also global auxiliar functions, that are ready to be embedded on [Conditions-Object](#ConditionsObjectDescription).
3835

3936
This library helps to simplify code, to make it intuitive and readable.
4037

@@ -91,6 +88,7 @@ This signature accepts an array of Conditions-Objects. If an item fulfill all co
9188
Condition-Object, it will be included in the results (and other Condition-Objects will not be evaluated for that item).
9289
This Signature is ideal to build (a kind of) `OR` statements that cannot be expressed in a single Conditions-Object.
9390
Examples:
91+
9492
```Javascript
9593
// Given an Array of objects representing persons, called 'peopleArray'
9694
// Task: find all single men between 20 and 30 years old and all married woman between 25 and 35 years old

0 commit comments

Comments
 (0)