Skip to content

Commit 8d42809

Browse files
author
DESKTOP-CLP1LAB\detky
committed
Readme update
1 parent d52067e commit 8d42809

File tree

1 file changed

+39
-28
lines changed

1 file changed

+39
-28
lines changed

README.md

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,47 +7,58 @@ To see it by yourself, please check how many time you need to find out what is d
77

88
```javascript
99
// Given an Array of objects representing persons, called 'peopleArray'
10-
// Plain js
11-
var result = [];
12-
for(var i = 0, l = peopleArray.length; i < l; i++) {
13-
var item = peopleArray[i];
10+
var result = 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?
19+
20+
```javascript
21+
// Given an Array of objects representing persons, called 'peopleArray'
22+
var result = [], i = 0, l, item;
23+
for(l = peopleArray.length; i < l; i++) {
24+
item = peopleArray[i];
1425
if(item.age > 18 && item.age < 70 && item.gender === 'M') {
1526
result.push(item);
1627
}
1728
}
1829
result.sort(function (a, b) {
1930
return a.lastName.toLowerCase().localeCompare(b.lastName.toLowerCase());
20-
})
21-
```
22-
23-
And how long for this one?
24-
25-
```javascript
26-
//using PowerArray
27-
var result = peopleArray
28-
.Where({ age: Between(18,70), gender: 'M'})
29-
.Sort({ lastName: Sort.AscendingIgnoringCase});
31+
});
32+
for(i = 0, l = result.length; i < l; i++) {
33+
console.debug(i + ' ' + result[i].name); //do something
34+
}
3035
```
3136

32-
Both codes do exactly the same thing, but the second is much easier to understand. It uses the **Where** and **Sort** PowerArray methods.
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.
3338

34-
This small example express what this library does: **it simplifies your code. Makes it intuitive, more readable. Functional.**
39+
This library helps to simplify code, to make it intuitive and readable.
3540

36-
**PowerArray** extends the Array prototype by adding additional features to work with any array in a compact and intuitive way.
41+
**PowerArray** extends the Array prototype by adding additional features to work with **any** array.
3742

3843
[Worried about changes on the Array Prototype?](#ArrayPrototypeChanges)
3944

40-
## Filtering with the **Where** function
41-
To simplify filtering tasks, PowerArray relies mainly on the **<a name="#WhereFunction">Where</a>** function, which offers a standard way to formulate
42-
filtering conditions by using **Conditions-objects**.
45+
<a name="#usage"></a>
46+
# Usage
47+
48+
//TODO
49+
50+
PowerArray adds also some auxiliary functions to avoid writing the same snippets over and over again. All they are accesible after loading the library, [click here for a complete list](#WherePAStandardFunction).
51+
52+
<a name="#WhereFunction"></a>
53+
## Filtering - The **.Where()** function
54+
To simplify filtering tasks, PowerArray relies mainly on the **Where** function, which offers a standard mechanism to formulate filtering conditions.
4355

44-
The return value of a *where* function call, is always an array of references to all items (of the original array) that fulfilled the given conditions.
45-
Filter conditions can be expressed in form of functions or by using Conditions-Object (by far the most comfortable way).
56+
> The return value of a **where** function call, ***is ALWAYS a new array***, in which each position is a reference to an item on your original array that fulfilled the conditions. The *Where* function doesn't change anything on the original array, it just creates a new array of references to all matching elements. Because it returns an array, it's also chainable with other PowerArray functions like <a href="#SortDescription">Sort</a> or <a href="#RunEachDescription">RunEach</a>.
4657
47-
It is very important to [understand **conditions-object**](#ConditionsObjectDescription) before you start using the **Where** function!
58+
You can pass conditions to the *Where* function (first argument in all signatures) as functions or by using [**Conditions-objects**](#ConditionsObjectDescription)</a>. It is necessary to understand [**Conditions-objects**](#ConditionsObjectDescription) before you start using the **Where** function.
4859

49-
### Where function Signatures:
50-
> **.Where**(conditionsObject ,*keepOrder*)
60+
### Signatures:
61+
> **anyArray.Where**(conditionsObject ,*keepOrder*)
5162
* **conditionsObject** => type `Object` (a Conditions-Object)
5263
* **keepOrder** => type `boolean`, indicating if the original order should be kept or not. Optional, default false.
5364
@@ -89,14 +100,14 @@ Examples:
89100
]);
90101

91102
// Given an array of orders called 'ordersArray'
92-
// Task: find all invoices from location "Sydney" having an amount <= 1000, or with an amount > 50000 (location independent)
103+
// Task: find all invoices "from location "Sydney" having an amount <= 1000" or "having amount > 50000, regardless location"
93104
var result = ordersArray.Where(
94105
{ amount : SmallerOrEqualThan(1000), location : 'Sydney' }, // Auxiliar function 'SmallerOrEqualThan' used
95106
{ amoung : GreatherThan(50000) } // Auxiliar function 'GreatherThan' used
96107
);
97108

98109
// In this two exmaples, we have multiple criterions that overlap each oder (age on the first example, amount on the second).
99-
// This overlap makes impossible to formulate both criterions on a single Conditions-Object, and that's why it's neccesary to use this signature.
110+
// This overlap makes impossible to formulate both criteria on a single Conditions-Object, and that's why it's neccesary to use this signature in such cases.
100111
```
101112

102113
> **.Where**(func ,*keepOrder*)
@@ -155,7 +166,7 @@ It just adds new functions, and only if the desired names (or pointers) are not
155166

156167
#### how does it works:
157168
Basically, PowerArray loads everything he needs to work on his own global object called "pa", as many frameworks do. The "pa" object is a container,
158-
in which there are multiple functions. Some are designed to work with any Array-prototyped object (defined at pa.prototypedFunctions_Array), and others
169+
in which there are multiple functions. Some of this functions, are designed to work with any object with having Array as prototype or (array like object) object, and others
159170
designed to operate globally (defined at pa.auxiliaryFunctions).
160171
During the initialization process, each of such functions is is evaluated, to check if the name is already in use before modifying anything.
161172
Only if they are free, a pointer to the corresponding pa function is set on the prototype array, or the global scope.

0 commit comments

Comments
 (0)