mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-11 22:28:45 +01:00
Merge pull request #220 from bjorn/count_predicate
Added Sequence.count(predicate)
This commit is contained in:
@ -11,11 +11,11 @@ Appends `item` to the end of the list.
|
||||
|
||||
### **clear**()
|
||||
|
||||
Removes all items from the list.
|
||||
Removes all elements from the list.
|
||||
|
||||
### **count**
|
||||
|
||||
The number of items in the list.
|
||||
The number of elements in the list.
|
||||
|
||||
### **insert**(index, item)
|
||||
|
||||
|
||||
@ -34,6 +34,24 @@ Otherwise, returns `false`.
|
||||
|
||||
Returns whether the sequence contains any element equal to the given element.
|
||||
|
||||
### **count**
|
||||
|
||||
The number of elements in the sequence.
|
||||
|
||||
Unless a more efficient override is available, this will iterate over the
|
||||
sequence in order to determine how many elements it contains.
|
||||
|
||||
### **count**(predicate)
|
||||
|
||||
Returns the number of elements in the sequence that pass the `predicate`.
|
||||
|
||||
Iterates over the sequence, passing each element to the function `predicate`
|
||||
and counting the number of times the returned value evaluates to `true`.
|
||||
|
||||
:::dart
|
||||
[1, 2, 3].count {|n| n > 2} // 1.
|
||||
[1, 2, 3].count {|n| n < 4} // 3.
|
||||
|
||||
### **join**(sep)
|
||||
|
||||
Returns a string representation of the list. The string representations of the
|
||||
|
||||
Reference in New Issue
Block a user