feat: add count method to Sequence class with iteration-based element tally
Implement a `count` method on the `Sequence` class that iterates over all elements and returns the total number. The method uses a simple for-loop to increment a counter for each element, providing a generic way to determine sequence length without requiring a separate length property. Includes a test sequence that yields values 1 through 10 to verify the count returns 10.
This commit is contained in:
@@ -1,4 +1,12 @@
|
||||
class Sequence {
|
||||
count {
|
||||
var result = 0
|
||||
for (element in this) {
|
||||
result = result + 1
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
map(f) {
|
||||
var result = new List
|
||||
for (element in this) {
|
||||
|
||||
Reference in New Issue
Block a user