diff --git a/Nasal/std/Vector.nas b/Nasal/std/Vector.nas index 2b81dbb49..ac93aaa71 100644 --- a/Nasal/std/Vector.nas +++ b/Nasal/std/Vector.nas @@ -120,6 +120,15 @@ var Vector = { die("ValueError: item not in the vector"); }, + contains: func (item) { + # Return true if the vector contains the item, false otherwise + + var err = []; + call(Vector.index, [item], me, err); + + return size(err) == 0; + }, + remove: func (item) { # Remove the first occurrence of the given item. Raises a # ValueError if the item is not present in the vector. diff --git a/Nasal/std/Vector.nas.test b/Nasal/std/Vector.nas.test index 78dc257e3..0f590324d 100644 --- a/Nasal/std/Vector.nas.test +++ b/Nasal/std/Vector.nas.test @@ -108,6 +108,10 @@ REQUIRE_EQUAL(x.size(), 4); # index(): REQUIRE_EQUAL(x.index("c"), 2); +# contains(): +REQUIRE_EQUAL(x.contains("c"), 1); +REQUIRE_EQUAL(x.contains("e"), 0); + # remove(): x.remove("c"); REQUIRE_EQUAL(x.vector, ["a", "b", "d"]);