Site under construction! :3
count(condition: any)
ξ―
Definitionξ―
(method) func array.count(condition: any) -> number: count = 0 if type(condition) is function: count += 1 if condition(element) for element in self else: count += 1 if element == condition for element in self return count
Returns the number of elements in the array that match condition
.
Pigeonξ―
> arr = ["a", "b", "c", "a", "b", "a"] > arr.count("a") 3
Parametersξ―
condition
ξ―
An object.
- If a
function
, return the number of elements in the array that return true when passed as arguments into it.
Pigeonξ―
> arr = [0, 1, 2, 3, 4] > arr.count(el => el >= 3) 2
- Else, return the number of elements in the array that are equal to
condition
.