You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
33
38
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.
35
40
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.
37
42
38
43
[Worried about changes on the Array Prototype?](#ArrayPrototypeChanges)
39
44
40
-
## Filtering with the **Where** function
41
-
To simplify filtering tasks, PowerArray relies mainly on the **<aname="#WhereFunction">Where</a>** function, which offers a standard way to formulate
42
-
filtering conditions by using **Conditions-objects**.
45
+
<aname="#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
+
<aname="#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.
43
55
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 <ahref="#SortDescription">Sort</a> or <ahref="#RunEachDescription">RunEach</a>.
46
57
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.
* **conditionsObject** => type `Object` (a Conditions-Object)
52
63
* **keepOrder** => type `boolean`, indicating if the original order should be kept or not. Optional, default false.
53
64
@@ -89,14 +100,14 @@ Examples:
89
100
]);
90
101
91
102
// 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"
93
104
var result =ordersArray.Where(
94
105
{ amount :SmallerOrEqualThan(1000), location :'Sydney' }, // Auxiliar function 'SmallerOrEqualThan' used
95
106
{ amoung :GreatherThan(50000) } // Auxiliar function 'GreatherThan' used
96
107
);
97
108
98
109
// 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.
100
111
```
101
112
102
113
> **.Where**(func ,*keepOrder*)
@@ -155,7 +166,7 @@ It just adds new functions, and only if the desired names (or pointers) are not
155
166
156
167
#### how does it works:
157
168
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
159
170
designed to operate globally (defined at pa.auxiliaryFunctions).
160
171
During the initialization process, each of such functions is is evaluated, to check if the name is already in use before modifying anything.
161
172
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