-
Notifications
You must be signed in to change notification settings - Fork 5
/
CPArray+extensions.j
51 lines (41 loc) · 967 Bytes
/
CPArray+extensions.j
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
* CPArray+extensions.j
* GithubIssues
*
* Created by Alexander Ljungberg on May 12, 2011.
* Copyright 2011, WireLoad Inc. All rights reserved.
*/
@import "CPArray+extensions.j"
@implementation CPArray (CountUsingPredicate)
/*!
Return the count of objects matching the predicate. This is a fast version of:
<pre><code>
[[array filteredArrayUsingPredicate:predicate] count];
</code></pre>
*/
- (void)countUsingPredicate:(CPPredicate)predicate
{
if (!predicate)
return 0;
var count = [self count],
r = 0;
while (count--)
{
if ([predicate evaluateWithObject:self[count]])
r++;
}
return r;
}
/*!
Because sometimes it's nice to have a deep copy of an array
*/
+ (CPArray)arrayWithDeepCopyOfArray:(CPArray)anArray
{
var newArray = [],
i = 0,
c = anArray.length;
for (; i < c; i++)
newArray.push([anArray[i] copy]);
return newArray;
}
@end