You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: challenges/objects-challenges.md
+59-29Lines changed: 59 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,21 +10,22 @@
10
10
1.[Create an array of pair of values (key, value) from an object and store it in a map. Consider the object is not nested](#Q4)
11
11
1.[Create an object with a property 'marks' which cannot be set to a value less than 0](#Q5)
12
12
1.[Create an object which has a property 'userid' which can only be set once and will be a read only property](#Q6)
13
-
1.[Design a function which takes an array as input and returns a function 'next', calling which fetches a value one by one](#Q7)
14
-
1.[Create an object 'obj' with functions assigned to keys. Show how can we achieve 'obj.func1().func2().func3()' considering func1, func2, func3 are object keys](#Q8)
15
-
1.[Create an object with property counter which keeps incrementing on every access](#Q9)
16
-
1.[Create an object and make it behave like an array which allows push and pop operations on items](#Q10)
17
-
1.[Write a function which can be used to deeply compare 2 nested objects](#Q11)
18
-
1.[Design a class for employee which takes id and name in during construction of object and has a salary property](#Q12)
19
-
1.[Write a program to make all the properties of an object ready only but allow the addition of new properties](#Q13)
20
-
1.[Write a program which can return a boolean if value is present in the range with given start and end values in an object](#Q14)
21
-
1.[Write a function which accepts a topic and a list of related tags to store the information. The same function should return all the topics when requested with a tagname](#Q15)
22
-
1.[Write a function which accepts a collection of values & an iteratee as arguments and returns a grouped object](#Q16)
23
-
1.[Create a constructor function which allows its functions present on prototype to be accessed only by the objects created by calling it](#Q17)
24
-
1.[Design a utility on an array of objects where the access can be made to the object using index (as usual) and also from primary key of the object](#Q18)
25
-
1.[Write a function which receives an object and returns a true if the object has circular reference](#Q19)
26
-
1.[Write a code which can eliminate circular references in an object (Cyclic reference in an object)](#Q20)
27
-
1.[Provide an object on which a value can be set to nested property even if it does not exist](#Q21)
13
+
1.[Stringify an object by excluding the 'password' property](#Q7)
14
+
1.[Design a function which takes an array as input and returns a function 'next', calling which fetches a value one by one](#Q8)
15
+
1.[Create an object 'obj' with functions assigned to keys. Show how can we achieve 'obj.func1().func2().func3()' considering func1, func2, func3 are object keys](#Q9)
16
+
1.[Create an object with property counter which keeps incrementing on every access](#Q10)
17
+
1.[Create an object and make it behave like an array which allows push and pop operations on items](#Q11)
18
+
1.[Write a function which can be used to deeply compare 2 nested objects](#Q12)
19
+
1.[Design a class for employee which takes id and name in during construction of object and has a salary property](#Q13)
20
+
1.[Write a program to make all the properties of an object ready only but allow the addition of new properties](#Q14)
21
+
1.[Write a program which can return a boolean if value is present in the range with given start and end values in an object](#Q15)
22
+
1.[Write a function which accepts a topic and a list of related tags to store the information. The same function should return all the topics when requested with a tagname](#Q16)
23
+
1.[Write a function which accepts a collection of values & an iteratee as arguments and returns a grouped object](#Q17)
24
+
1.[Create a constructor function which allows its functions present on prototype to be accessed only by the objects created by calling it](#Q18)
25
+
1.[Design a utility on an array of objects where the access can be made to the object using index (as usual) and also from primary key of the object](#Q19)
26
+
1.[Write a function which receives an object and returns a true if the object has circular reference](#Q20)
27
+
1.[Write a code which can eliminate circular references in an object (Cyclic reference in an object)](#Q21)
28
+
1.[Provide an object on which a value can be set to nested property even if it does not exist](#Q22)
### Design a function which takes an array as input and returns a function 'next', calling which fetches a value one by one
205
235
206
236
- The function returned `next` will return an object which contains value and done properties
@@ -234,7 +264,7 @@ it.next().done; // true
234
264
235
265
<br />
236
266
237
-
#### Q8
267
+
#### Q9
238
268
### Create an object 'obj' with functions assigned to keys. Show how can we achieve 'obj.func1().func2().func3()' considering func1, func2, func3 are object keys
239
269
240
270
- For achieving chaining functionality, each function can return the calling context itself so that context is retained
@@ -276,7 +306,7 @@ Order of calling the functions does not matter as all the functions are returnin
276
306
277
307
<br />
278
308
279
-
#### Q9
309
+
#### Q10
280
310
### Create an object with property counter which keeps incrementing on every access
281
311
```js
282
312
constobj=counterObject();
@@ -312,7 +342,7 @@ Symbol is used to maintain the private variable in the object. Using the private
312
342
313
343
<br />
314
344
315
-
#### Q10
345
+
#### Q11
316
346
### Create an object and make it behave like an array which allows push and pop operations on items
317
347
318
348
- Object does not have by default a property named 'length' and hence we can define it on object which helps to track the length
@@ -341,7 +371,7 @@ As the context for array methods is set object, length of the object changes whe
341
371
342
372
<br />
343
373
344
-
#### Q11
374
+
#### Q12
345
375
### Write a function which can be used to deeply compare 2 nested objects
346
376
```js
347
377
// Example
@@ -396,7 +426,7 @@ Stringification of both objects and comparision will also work, but fails on key
396
426
397
427
<br />
398
428
399
-
#### Q12
429
+
#### Q13
400
430
### Design a class for employee which takes id and name in during construction of object and has a salary property
401
431
402
432
- Classes are a template for creating objects. They encapsulate data with code to work on that data
@@ -444,7 +474,7 @@ Class in JavaScript is functionality to achieve class based model on top of prot
444
474
445
475
<br />
446
476
447
-
#### Q13
477
+
#### Q14
448
478
### Write a program to make all the properties of an object ready only but allow the addition of new properties
449
479
450
480
- The exisiting properties of the object can be made read only with `set` keyword using Proxy
@@ -472,7 +502,7 @@ If condition takes care whether the property is new or existing to handle the re
472
502
473
503
<br />
474
504
475
-
#### Q14
505
+
#### Q15
476
506
### Write a program which can return a boolean if value is present in the range with given start and end values in an object
477
507
```js
478
508
// Example
@@ -497,7 +527,7 @@ range = new Proxy(range, {
497
527
498
528
<br />
499
529
500
-
#### Q15
530
+
#### Q16
501
531
### Write a function which accepts a topic and a list of related tags to store the information. The same function should return all the topics when requested with a tagname
502
532
```js
503
533
// Example
@@ -542,7 +572,7 @@ function TagManager() {
542
572
543
573
<br />
544
574
545
-
#### Q16
575
+
#### Q17
546
576
### Write a function which accepts a collection of values & an iteratee as arguments and returns a grouped object
547
577
```js
548
578
// Example
@@ -570,7 +600,7 @@ function groupBy(values, iteratee) {
570
600
571
601
<br />
572
602
573
-
#### Q17
603
+
#### Q18
574
604
### Create a constructor function which allows its functions present on prototype to be accessed only by the objects created by calling it
575
605
576
606
- The list of objects created by the function can be kept in track using a collection object inside function
0 commit comments