1
0
Fork 0

Nasal: std.Vector: add 'contains' method (by onox).

This commit is contained in:
Thomas Geymayer 2014-12-23 14:40:29 +01:00
parent 5e2a37be56
commit d930e3f2fa
2 changed files with 13 additions and 0 deletions

View file

@ -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.

View file

@ -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"]);