Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: document length() operator

...

Code Block
languagejavascript
themeConfluence
{ "colors" : "many",
  "pi" : [3,1,4,1,5,6,9],
  "foo" : {"bar" : {"10":"I like cheese"}}
}

The hash path ["foo", "bar"] references the following map inside the data structure:

Code Block
languagejavascript
themeConfluence
{"bar" : {"10":"I like cheese"}}

get()

Returns the value at the given hash-path. This is the same as the foo{path}

Code Block
languagejavascript
themeConfluence
a = {
  "colors" : "many",
  "pi" : [3,1,4,1,5,6,9],
  "foo" : {"bar" : {"10":"I like cheese"}}
};

a.get(["foo", "bar", "10"])
// "I like cheese"

a{["foo", "bar", "10"]}
// "I like cheese"

...

Code Block
languagejavascript
themeConfluence
a = { "colors" : "many",
      "pi" : [3,1,4,1,5,6,9],
      "foo" : {"bar" : {"10": "I like cheese", "a" : 12}}
    };
b = a.keys();               // b = ["colors", "pi", "foo"]
c = a.keys(["foo", "bar"]); // c = [10, "a"]

length()

The length() operator returns the number of elements in the map to which it is applied.

Code Block
a = { "colors" : "many",
      "pi" : [3,1,4,1,5,6,9],
      "foo" : {"bar" : {"10": "I like cheese", "a" : 12}}
    };
b = a.length();                // b = 3
c = a{"foo"}.length();         // c = 1
d = a{["foo","bar"]}.length(); // d = 2

map()

The map() operator returns a map that contains the results of applying the function given as the operator's argument to each key-value pair from the original map. The function given as an argument must take two arguments: the first will be the value and the second the key. The result will be a map with the same keys, each key mapped to the result of the function. The length of the resulting map will be equal to the length of the target map. For example:

...

Code Block
languagejavascript
themeConfluence
a = { "colors" : "many",
      "pi" : [3,1,4,1,5,6,9],
      "foo" : {"bar" : {"10": "I like cheese", "a" : 12}}
    };
b = a.values();               // b = ["many", [3,1,4,1,5,6,9], {"bar" : {"10": "I like cheese", "a" : 12}}]
c = a.values(["foo", "bar"]); // c = ["I like cheese", 12]

...