diff --git a/README.md b/README.md
index 531ebbb2..9391542f 100644
--- a/README.md
+++ b/README.md
@@ -273,7 +273,16 @@ Returns the value for the specified *key* string. If the map does not have an en
# map.set(key, value)
-Sets the *value* for the specified *key* string. If the map previously had an entry for the same *key* string, the old entry is replaced with the new value. Returns the map, allowing chaining.
+Sets the *value* for the specified *key* string. If the map previously had an entry for the same *key* string, the old entry is replaced with the new value. Returns the map, allowing chaining. For example:
+
+```js
+var m = map()
+ .set("foo", 1)
+ .set("bar", 2)
+ .set("baz", 3);
+
+m.get("foo"); // 1
+```
# map.remove(key)
@@ -326,7 +335,16 @@ Returns true if and only if this set has an entry for the specified *value* stri
# set.add(value)
-Adds the specified *value* string to this set. Returns the set, allowing chaining.
+Adds the specified *value* string to this set. Returns the set, allowing chaining. For example:
+
+```js
+var s = set()
+ .add("foo")
+ .add("bar")
+ .add("baz");
+
+s.has("foo"); // true
+```
# set.remove(value)
diff --git a/package.json b/package.json
index c2e10b7f..3bb2db09 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "d3-arrays",
- "version": "0.2.1",
+ "version": "0.3.0",
"description": "Array manipulation, ordering, searching, summarizing, etc.",
"keywords": [
"d3",
diff --git a/test/map-test.js b/test/map-test.js
index cb8acac4..5a52d369 100644
--- a/test/map-test.js
+++ b/test/map-test.js
@@ -92,10 +92,8 @@ tape("map.size() returns the number of distinct keys", function(test) {
});
tape("map.clear() removes all entries", function(test) {
- var m = arrays.map();
- m.set("foo", 1);
- m.set("bar", 2);
- m.set("foo", 3);
+ var m = arrays.map().set("foo", 1).set("bar", 2).set("foo", 3);
+ test.equal(m.size(), 2);
m.clear();
test.equal(m.size(), 0);
test.deepEqual(m.entries(), []);
@@ -159,9 +157,7 @@ tape("map.keys() returns an array of string keys", function(test) {
});
tape("map.keys() properly unescapes zero-prefixed keys", function(test) {
- var m = arrays.map();
- m.set("__proto__", 42);
- m.set("$weird", 42);
+ var m = arrays.map().set("__proto__", 42).set("$weird", 42);
test.deepEqual(m.keys().sort(), ["$weird", "__proto__"]);
test.end();
});
@@ -222,17 +218,13 @@ tape("map.has(key) empty maps do not have object built-ins", function(test) {
});
tape("map.has(key) can has keys using built-in names", function(test) {
- var m = arrays.map();
- m.set("__proto__", 42);
+ var m = arrays.map().set("__proto__", 42);
test.equal(m.has("__proto__"), true);
test.end();
});
tape("map.has(key) can has keys with null or undefined properties", function(test) {
- var m = arrays.map();
- m.set("", "");
- m.set("null", null);
- m.set("undefined", undefined);
+ var m = arrays.map().set("", "").set("null", null).set("undefined", undefined);
test.equal(m.has(""), true);
test.equal(m.has("null"), true);
test.equal(m.has("undefined"), true);
@@ -348,10 +340,7 @@ tape("map.set(key, value) can replace values", function(test) {
});
tape("map.set(key, value) can set null, undefined or empty string values", function(test) {
- var m = arrays.map();
- m.set("", "");
- m.set("null", null);
- m.set("undefined", undefined);
+ var m = arrays.map().set("", "").set("null", null).set("undefined", undefined);
test.equal(m.get(""), "");
test.equal(m.get("null"), null);
test.equal(m.get("undefined"), undefined);
diff --git a/test/set-test.js b/test/set-test.js
index 8697a948..33387947 100644
--- a/test/set-test.js
+++ b/test/set-test.js
@@ -52,10 +52,8 @@ tape("set.size() returns the number of distinct values", function(test) {
});
tape("set.clear() removes all values", function(test) {
- var s = arrays.set();
- s.add("foo");
- s.add("bar");
- s.add("foo");
+ var s = arrays.set().add("foo").add("bar").add("foo");
+ test.equal(s.size(), 2);
s.clear();
test.equal(s.size(), 0);
test.deepEqual(s.values(), []);
@@ -202,15 +200,13 @@ tape("set.add(value) returns the set", function(test) {
});
tape("set.add(value) can add values using built-in names", function(test) {
- var s = arrays.set();
- s.add("__proto__");
+ var s = arrays.set().add("__proto__");
test.equal(s.has("__proto__"), true);
test.end();
});
tape("set.add(value) can add values using zero-prefixed names", function(test) {
- var s = arrays.set();
- s.add("$weird");
+ var s = arrays.set().add("$weird");
test.equal(s.has("$weird"), true);
test.end();
});
@@ -228,10 +224,7 @@ tape("set.add(value) coerces values to strings", function(test) {
});
tape("set.add(value) can add null, undefined or empty string values", function(test) {
- var s = arrays.set();
- s.add("");
- s.add("null");
- s.add("undefined");
+ var s = arrays.set().add("").add("null").add("undefined");
test.equal(s.has(""), true);
test.equal(s.has("null"), true);
test.equal(s.has("undefined"), true);