feat: move contains method from List to Sequence and add tests for List and Range
Add a generic `contains` implementation on the `Sequence` base class, removing the duplicate method from `List`. This allows all sequence types (including Range) to use the method without per-class redefinition. Include new test files for `List.contains` and `Range.contains` covering ordered, backwards, and exclusive ranges.
This commit is contained in:
+9
-9
@@ -1,4 +1,13 @@
|
||||
class Sequence {
|
||||
contains(element) {
|
||||
for (item in this) {
|
||||
if (element == item) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
count {
|
||||
var result = 0
|
||||
for (element in this) {
|
||||
@@ -92,15 +101,6 @@ class List is Sequence {
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
contains(element) {
|
||||
for (item in this) {
|
||||
if (element == item) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
class Map {
|
||||
|
||||
Reference in New Issue
Block a user