Skip to content

Commit 16f5c45

Browse files
authored
Merge pull request #30 from Voltra/master
Predicate base collection manipulation
2 parents 8508aba + e668b04 commit 16f5c45

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed

implementations/every.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
*
3+
every() exectues a provided *predicate* on each element of
4+
the array until it is not fulfilled.
5+
6+
every() has two parameters:
7+
8+
- the predicate callback function
9+
- a *this* argument for the callback. If none is provided, *this* will not be set in the predicate
10+
11+
The predicate function one to three arguments:
12+
13+
- the value of current element
14+
- the index of the current element
15+
- the Array object being traversed
16+
17+
If the predicate is not fulfilled then the method will exit early (and return false).
18+
19+
Calling every on an empty array will return true.
20+
*/
21+
Array.prototype.myEvery = function myEvery(predicate, thisArg){
22+
for(var i = 0 ; i < this.length ; ++i){
23+
if(!predicate.call(thisArg, this[i], i, this))
24+
return false;
25+
}
26+
27+
return true;
28+
}

implementations/none.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
*
3+
none() exectues a provided *predicate* on each element of
4+
the array until it is fulfilled.
5+
6+
none() has two parameters:
7+
8+
- the predicate callback function
9+
- a *this* argument for the callback. If none is provided, *this* will not be set in the predicate
10+
11+
The predicate function one to three arguments:
12+
13+
- the value of current element
14+
- the index of the current element
15+
- the Array object being traversed
16+
17+
If the predicate is fulfilled then the method will exit early (and return false).
18+
19+
Calling none on an empty array will return true.
20+
*/
21+
Array.prototype.myNone = function myNone(predicate, thisArg){
22+
for(var i = 0 ; i < this.length ; ++i){
23+
if(predicate.call(thisArg, this[i], i, this))
24+
return false;
25+
}
26+
27+
return true;
28+
}

implementations/some.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
*
3+
some() exectues a provided *predicate* on each element of
4+
the array until it is fulfilled.
5+
6+
some() has two parameters:
7+
8+
- the predicate callback function
9+
- a *this* argument for the callback. If none is provided, *this* will not be set in the predicate
10+
11+
The predicate function one to three arguments:
12+
13+
- the value of current element
14+
- the index of the current element
15+
- the Array object being traversed
16+
17+
If the predicate is fulfilled then the method will exit early (and return true).
18+
19+
Calling some on an empty array will return false.
20+
*/
21+
Array.prototype.mySome = function mySome(predicate, thisArg){
22+
for(var i = 0 ; i < this.length ; ++i){
23+
if(predicate.call(thisArg, this[i], i, this))
24+
return true;
25+
}
26+
27+
return false;
28+
};

0 commit comments

Comments
 (0)