This problem will work with JSON-formatted data representing a "vocabulary set" of terms and definitions in the following JSON schema:
{
"setname" : String,
"terms" : [
{ "term" : String, "pos" : String, "definition" : String },
{ "term" : String, "pos" : String, "definition" : String },
...
]
}
Each vocabulary set has a name and a collection of terms, each
having a single POS (part-of-speech type) and definition.
Write a function named termsWithPOS
that takes
the following two parameters:
- A JavaScript object called
vocab
representing a vocabulary set
- A string parameter called
posType
representing a part-of-speech (e.g. "noun", "adjective", or "verb")
Your function should return an array of all words that have a pos
value matching the given posType
, ignoring letter-casing.
For example, if the following vocabulary set is defined:
{
"setname" : "SAT Set 1",
"terms" : [
{ "term" : "abate",
"pos" : "verb",
"definition" : "lessen" },
{ "term" : "abnegation",
"pos" : "noun",
"definition" : "the denial of a doctrine or belief" },
{ "term" : "adept",
"pos" : "adjective",
"definition" : "skillful" },
{ "term" : "advocate",
"pos" : "noun",
"definition" : "a person who pleads for a person, cause, or idea" },
{ "term" : "adroit",
"pos" : "adjective",
"definition" : "skillful" },
{ "term" : "annex",
"pos" : "noun",
"definition" : "extension to a building" },
{ "term" : "annex",
"pos" : "verb",
"definition" : "to take away from" },
{ "term" : "antediluvian",
"pos" : "adjective",
"definition" : "very old" }
]
};
then the call termsWithPOS(vocab, "NOUN")
should return the following array:
["abnegation", "advocate", "annex"]
You may assume that the passed vocab
is non-null but if the "terms" key is missing,
your function should throw an exception with the message,
"Passed object must have 'terms' key".
You may otherwise assume all of the keys of each object in the "terms" array are defined
and have the datatype specified in the provided schema.