|
1 | | -#Academy Online Catalogs |
2 | | - |
3 | | -* Implement a functionality to serve an Academy Online Catalogs |
4 | | - * The catalog contains a set of items |
5 | | - |
6 | | -## `Item` |
7 | | -has the following: |
8 | | - |
9 | | -* properties |
10 | | - * `id` |
11 | | - * A **number** unique for all items |
12 | | - * Generated at object creation |
13 | | - * `description` |
14 | | - * A **non-empty** string |
15 | | - * Passed as parameter to a constructor or init function |
16 | | - * `name` |
17 | | - * A string with length **between 2 and 40** characters, inclusive |
18 | | - * Passed as parameter to a constructor or init function |
19 | | - |
20 | | -## `Book` |
21 | | -has the following: |
22 | | - |
23 | | -* inherits Item |
24 | | -* properties |
25 | | - * isbn |
26 | | - * A string with length **exactly 10 or 13** |
27 | | - * Can contain **only digits** |
28 | | - * Passed to a constructor or init function |
29 | | - * genre |
30 | | - * A string with length **between 2 and 20** characters, inclusive |
31 | | - * Passed as parameter to a constructor or init function |
32 | | - |
33 | | -## `Media` |
34 | | -each has the following: |
35 | | - |
36 | | -* inherits Item |
37 | | -* properties |
38 | | - * duration |
39 | | - * A number greater than 0 |
40 | | - * Passed as parameter to a constructor or init function |
41 | | - * rating |
42 | | - * A number between 1 and 5, inclusive |
43 | | - * Passed as parameter to a constructor or init function |
44 | | - |
45 | | -## `Catalog` |
46 | | -has the following: |
47 | | - |
48 | | -* properties: |
49 | | - * id |
50 | | - * A **number** unique for all catalogs |
51 | | - * Generated at object creation |
52 | | - * name |
53 | | - * A string with length **between 2 and 40** characters, inclusive |
54 | | - * Passed as parameter to a constructor or init function |
55 | | - * items |
56 | | - * An array where the added items are stored |
57 | | - * (this is for testing reasons make a direct reference and do not use `.slice()`) |
58 | | -* methods: |
59 | | - * add(item1, item2, item3, ...) |
60 | | - * Add items to this catalog instance |
61 | | - * Items can be one or more |
62 | | - * This method should enable **chaining** |
63 | | - * Throws if: |
64 | | - * No items are passed |
65 | | - * Any of the items is **not an Item instance** or **not an Item-like object** |
66 | | - * **none of the items must be added** in case of error |
67 | | - * add(itemsArray) |
68 | | - * Add items to this catalog instance |
69 | | - * Items are provided as an array |
70 | | - * The array can contain one or more items |
71 | | - * Throws if: |
72 | | - * The array is empty |
73 | | - * Any of the items is **not an Item instance** or **not an Item-like object** |
74 | | - * **none of the items must be added** in case of error |
75 | | - * find(id) |
76 | | - * **Returns the left most item** that has the provided `id` |
77 | | - * **Returns null** if there is no item with the provided `id` |
78 | | - * Throws if: |
79 | | - * no arguments are passed |
80 | | - * `id` is not a number |
81 | | - * find(options) |
82 | | - * **Returns an array of items**, that meet the requirements in options |
83 | | - * **Returns an empty array**, if no item meets the requirements |
84 | | - * The requirements are provided as an `options` object |
85 | | - * The `options` object can have keys `id` or/and `name` |
86 | | - * Each item that matches all the properties and their values in the `options` object must be returned |
87 | | - * __Example:__ |
88 | | - |
89 | | - //having items [{name: 'Samsung Galaxy S2', id: 2}, {name: 'Peralnya Hubava', id: 3}, {name: 'Samsung Galaxy S2', id: 4}] |
90 | | - |
91 | | - //find({name: 'Samsung Galaxy S2'}) |
92 | | - //returns [{name: 'Samsung Galaxy S2', id: 2}, {name: 'Samsung Galaxy S2', id: 4}] |
93 | | - |
94 | | - //find({id: 3}) |
95 | | - //returns [{name: 'Peralnya Hubava', id: 3}] |
96 | | - |
97 | | - //find({id: 2, name: 'Samsung Galaxy S2'}) |
98 | | - //returns [{name: 'Samsung Galaxy S2', id: 2}] |
99 | | - |
100 | | - //find({id: 2, name: 'samsung gaLAxy s2'}) |
101 | | - //returns [{name: 'Samsung Galaxy S2', id: 2}] |
102 | | - |
103 | | - //find({id:6}) and find({name: 'Samsung'}) |
104 | | - //returns [] |
105 | | - |
106 | | - * search(pattern) |
107 | | - * **Returns an array of items** |
108 | | - * Each item **must contain** the pattern as substring either in its **name** or in its **description** |
109 | | - * **Returns an empty array**, if **none of the items** contain the pattern |
110 | | - * The `pattern` is a string containing at least 1 character |
111 | | - * The search is **case insensitive** |
112 | | - |
113 | | -##`BookCatalog` |
114 | | -has the following: |
115 | | - |
116 | | -* inherits Catalog |
117 | | -* methods: |
118 | | - * add(book1, book2, book3, ...) |
119 | | - * Extends parent's method |
120 | | - * Adds a throw when: |
121 | | - * Any of the books is **not a Book instance** or **not a Book-like object** |
122 | | - * **none of the books must be added** in case of error |
123 | | - * add(booksArray) |
124 | | - * Extends parent's method |
125 | | - * Adds a throw when: |
126 | | - * Any of the books is **not a Book instance** or **not a Book-like object** |
127 | | - * **none of the items must be added** in case of error |
128 | | - * getGenres() |
129 | | - * **Returns an array of lowercase strings** |
130 | | - * All the unique genres of books that are added |
131 | | - * find(options) |
132 | | - * Extends find(options) from parent, but adds a key `genre` |
133 | | - * i.e. books can be found by `id`, `name` and/or `genre` |
134 | | - |
135 | | -## `MediaCatalog` |
136 | | -has the following: |
137 | | - |
138 | | -* inherits Catalog |
139 | | -* methods: |
140 | | - * add(media1, media2, media3, ...) |
141 | | - * Extends parent's method |
142 | | - * Adds a throw when: |
143 | | - * Any of the media is **not a Media instance** or **not a Media-like object** |
144 | | - * **none of the media must be added** in case of error |
145 | | - * add(mediaArray) |
146 | | - * Extends parent's method |
147 | | - * Adds a throw when: |
148 | | - * Any of the media is **not a Media instance** or **not a Media-like object** |
149 | | - * **none of the media must be added** in case of error |
150 | | - * getTop(count) |
151 | | - * **Returns an array with the `id` and `name`** of the top `count` media **sorted by rating** |
152 | | - * Throws if |
153 | | - * Count is not a number |
154 | | - * Count is less than 1 |
155 | | - * getSortedByDuration |
156 | | - * **Returns an array of all the media in the catalog** |
157 | | - * The media must sorted by: |
158 | | - * descending by duration |
159 | | - * ascending by id |
160 | | - |
161 | | - |
162 | | -##Example: |
163 | | - |
164 | | - function solve(){ |
165 | | - return { |
166 | | - getBook: function (name, isbn, genre, description) { |
167 | | - //return a book instance |
168 | | - }, |
169 | | - getMedia: function (name, rating, duration, description) { |
170 | | - //return a media instance |
171 | | - } |
172 | | - getBookCatalog: function (name) { |
173 | | - //return a book catalog instance |
174 | | - }, |
175 | | - getMediaCatalog: function (name) { |
176 | | - //return a media catalog instance |
177 | | - } |
| 1 | +#Academy Online Catalogs |
| 2 | + |
| 3 | +* Implement a functionality to serve an Academy Online Catalogs |
| 4 | + * The catalog contains a set of items |
| 5 | + |
| 6 | +## `Item` |
| 7 | +has the following: |
| 8 | + |
| 9 | +* properties |
| 10 | + * `id` |
| 11 | + * A **number** unique for all items |
| 12 | + * Generated at object creation |
| 13 | + * `description` |
| 14 | + * A **non-empty** string |
| 15 | + * Passed as parameter to a constructor or init function |
| 16 | + * `name` |
| 17 | + * A string with length **between 2 and 40** characters, inclusive |
| 18 | + * Passed as parameter to a constructor or init function |
| 19 | + |
| 20 | +## `Book` |
| 21 | +has the following: |
| 22 | + |
| 23 | +* inherits Item |
| 24 | +* properties |
| 25 | + * isbn |
| 26 | + * A string with length **exactly 10 or 13** |
| 27 | + * Can contain **only digits** |
| 28 | + * Passed to a constructor or init function |
| 29 | + * genre |
| 30 | + * A string with length **between 2 and 20** characters, inclusive |
| 31 | + * Passed as parameter to a constructor or init function |
| 32 | + |
| 33 | +## `Media` |
| 34 | +each has the following: |
| 35 | + |
| 36 | +* inherits Item |
| 37 | +* properties |
| 38 | + * duration |
| 39 | + * A number greater than 0 |
| 40 | + * Passed as parameter to a constructor or init function |
| 41 | + * rating |
| 42 | + * A number between 1 and 5, inclusive |
| 43 | + * Passed as parameter to a constructor or init function |
| 44 | + |
| 45 | +## `Catalog` |
| 46 | +has the following: |
| 47 | + |
| 48 | +* properties: |
| 49 | + * id |
| 50 | + * A **number** unique for all catalogs |
| 51 | + * Generated at object creation |
| 52 | + * name |
| 53 | + * A string with length **between 2 and 40** characters, inclusive |
| 54 | + * Passed as parameter to a constructor or init function |
| 55 | + * items |
| 56 | + * An array where the added items are stored |
| 57 | + * (this is for testing reasons make a direct reference and do not use `.slice()`) |
| 58 | +* methods: |
| 59 | + * add(item1, item2, item3, ...) |
| 60 | + * Add items to this catalog instance |
| 61 | + * Items can be one or more |
| 62 | + * This method should enable **chaining** |
| 63 | + * Throws if: |
| 64 | + * No items are passed |
| 65 | + * Any of the items is **not an Item instance** or **not an Item-like object** |
| 66 | + * **none of the items must be added** in case of error |
| 67 | + * add(itemsArray) |
| 68 | + * Add items to this catalog instance |
| 69 | + * Items are provided as an array |
| 70 | + * The array can contain one or more items |
| 71 | + * Throws if: |
| 72 | + * The array is empty |
| 73 | + * Any of the items is **not an Item instance** or **not an Item-like object** |
| 74 | + * **none of the items must be added** in case of error |
| 75 | + * find(id) |
| 76 | + * **Returns the left most item** that has the provided `id` |
| 77 | + * **Returns null** if there is no item with the provided `id` |
| 78 | + * Throws if: |
| 79 | + * no arguments are passed |
| 80 | + * `id` is not a number |
| 81 | + * find(options) |
| 82 | + * **Returns an array of items**, that meet the requirements in options |
| 83 | + * **Returns an empty array**, if no item meets the requirements |
| 84 | + * The requirements are provided as an `options` object |
| 85 | + * The `options` object can have keys `id` or/and `name` |
| 86 | + * Each item that matches all the properties and their values in the `options` object must be returned |
| 87 | + * __Example:__ |
| 88 | + |
| 89 | + //having items [{name: 'Samsung Galaxy S2', id: 2}, {name: 'Peralnya Hubava', id: 3}, {name: 'Samsung Galaxy S2', id: 4}] |
| 90 | + |
| 91 | + //find({name: 'Samsung Galaxy S2'}) |
| 92 | + //returns [{name: 'Samsung Galaxy S2', id: 2}, {name: 'Samsung Galaxy S2', id: 4}] |
| 93 | + |
| 94 | + //find({id: 3}) |
| 95 | + //returns [{name: 'Peralnya Hubava', id: 3}] |
| 96 | + |
| 97 | + //find({id: 2, name: 'Samsung Galaxy S2'}) |
| 98 | + //returns [{name: 'Samsung Galaxy S2', id: 2}] |
| 99 | + |
| 100 | + //find({id: 2, name: 'samsung gaLAxy s2'}) |
| 101 | + //returns [{name: 'Samsung Galaxy S2', id: 2}] |
| 102 | + |
| 103 | + //find({id:6}) and find({name: 'Samsung'}) |
| 104 | + //returns [] |
| 105 | + |
| 106 | + * search(pattern) |
| 107 | + * **Returns an array of items** |
| 108 | + * Each item **must contain** the pattern as substring either in its **name** or in its **description** |
| 109 | + * **Returns an empty array**, if **none of the items** contain the pattern |
| 110 | + * The `pattern` is a string containing at least 1 character |
| 111 | + * The search is **case insensitive** |
| 112 | + |
| 113 | +##`BookCatalog` |
| 114 | +has the following: |
| 115 | + |
| 116 | +* inherits Catalog |
| 117 | +* methods: |
| 118 | + * add(book1, book2, book3, ...) |
| 119 | + * Extends parent's method |
| 120 | + * Adds a throw when: |
| 121 | + * Any of the books is **not a Book instance** or **not a Book-like object** |
| 122 | + * **none of the books must be added** in case of error |
| 123 | + * add(booksArray) |
| 124 | + * Extends parent's method |
| 125 | + * Adds a throw when: |
| 126 | + * Any of the books is **not a Book instance** or **not a Book-like object** |
| 127 | + * **none of the items must be added** in case of error |
| 128 | + * getGenres() |
| 129 | + * **Returns an array of lowercase strings** |
| 130 | + * All the unique genres of books that are added |
| 131 | + * find(options) |
| 132 | + * Extends find(options) from parent, but adds a key `genre` |
| 133 | + * i.e. books can be found by `id`, `name` and/or `genre` |
| 134 | + |
| 135 | +## `MediaCatalog` |
| 136 | +has the following: |
| 137 | + |
| 138 | +* inherits Catalog |
| 139 | +* methods: |
| 140 | + * add(media1, media2, media3, ...) |
| 141 | + * Extends parent's method |
| 142 | + * Adds a throw when: |
| 143 | + * Any of the media is **not a Media instance** or **not a Media-like object** |
| 144 | + * **none of the media must be added** in case of error |
| 145 | + * add(mediaArray) |
| 146 | + * Extends parent's method |
| 147 | + * Adds a throw when: |
| 148 | + * Any of the media is **not a Media instance** or **not a Media-like object** |
| 149 | + * **none of the media must be added** in case of error |
| 150 | + * getTop(count) |
| 151 | + * **Returns an array with the `id` and `name`** of the top `count` media **sorted by rating** |
| 152 | + * Throws if |
| 153 | + * Count is not a number |
| 154 | + * Count is less than 1 |
| 155 | + * getSortedByDuration |
| 156 | + * **Returns an array of all the media in the catalog** |
| 157 | + * The media must sorted by: |
| 158 | + * descending by duration |
| 159 | + * ascending by id |
| 160 | + |
| 161 | + |
| 162 | +##Example: |
| 163 | + |
| 164 | + function solve(){ |
| 165 | + return { |
| 166 | + getBook: function (name, isbn, genre, description) { |
| 167 | + //return a book instance |
| 168 | + }, |
| 169 | + getMedia: function (name, rating, duration, description) { |
| 170 | + //return a media instance |
| 171 | + } |
| 172 | + getBookCatalog: function (name) { |
| 173 | + //return a book catalog instance |
| 174 | + }, |
| 175 | + getMediaCatalog: function (name) { |
| 176 | + //return a media catalog instance |
| 177 | + } |
178 | 178 | }; |
0 commit comments