Skip to content

Commit 2ff3224

Browse files
authored
Update objects.mdx
1 parent 459766d commit 2ff3224

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

web/src/pages/challenges/objects.mdx

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -445,27 +445,27 @@ emp.getSalary(); // 11000
445445

446446
**Notes**
447447

448-
Class in JavaScript is a functionality to achieve class based model on top of prototype based programming model of JavaScript
448+
Class in JavaScript is a functionality to achieve a class-based model on top of the prototype-based programming model of JavaScript
449449

450450
**References**
451451

452452
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes
453453

454454
---
455455

456-
### 14. Write a program to make all the properties of an object read only but allow the addition of new properties
456+
### 14. Write a program to make all the properties of an object read-only but allow the addition of new properties
457457

458-
- The exisiting properties of the object can be made read only with `set` keyword using Proxy
458+
- The existing properties of the object can be made read-only with the `set` keyword using the Proxy
459459

460460
```js copy
461461
const readOnlyObj = new Proxy(obj, {
462462
get: function (target, key) {
463463
return target[key];
464464
},
465465

466-
set: function () {
466+
set: function (target, key, value) {
467467
if (target.hasOwnProperty(key)) {
468-
throw new Error("Object properties are read only");
468+
throw new Error("Object properties are read-only");
469469
}
470470
target[key] = value;
471471
},
@@ -474,15 +474,15 @@ const readOnlyObj = new Proxy(obj, {
474474

475475
**Notes**
476476

477-
If condition takes care whether the property is new or existing to handle the read only scenario
477+
If the condition takes care of whether the property is new or existing to handle the read-only scenario
478478

479479
**References**
480480

481481
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries
482482

483483
---
484484

485-
### 15. Write a program which can return a boolean if value is present in the range with given start and end values in an object
485+
### 15. Write a program that can return a boolean if value is present in the range with given start and end values in an object
486486

487487
```js copy
488488
// Example
@@ -507,7 +507,7 @@ range = new Proxy(range, {
507507

508508
---
509509

510-
### 16. 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
510+
### 16. Write a function that 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 tag name
511511

512512
```js copy
513513
// Example
@@ -520,8 +520,8 @@ tagManager.getTopics.getTopics("VDOM"); // React, Vue
520520
tagManager.getTopics.getTopics("JavaScript"); // React, Angular, Vue
521521
```
522522

523-
- The tags can be stored as keys and array of topics as values in a map
524-
- Function module can be desgined to expose 'addTags' and 'getTopics' by tagname
523+
- The tags can be stored as keys and an array of topics as values in a map
524+
- Function module can be designed to expose 'addTags' and 'getTopics' by tag name
525525

526526
```js copy
527527
function TagManager() {
@@ -552,16 +552,16 @@ function TagManager() {
552552

553553
---
554554

555-
### 17. Write a function which accepts a collection of values & an iteratee as arguments and returns a grouped object
555+
### 17. Write a function that accepts a collection of values & an iteratee as arguments and returns a grouped object
556556

557557
```js copy
558558
// Example
559559
groupBy([6.1, 4.2, 6.3], Math.floor); // { 6: [6.1, 6.3], 4: [4.2] }
560560
groupBy(["one", "two", "three"], "length"); // { 3: ['one', 'two'], 5: ['three'] }
561561
```
562562

563-
- As the 2nd argument is either a functin or property, the iteratee can be perfrom accordingly on the value of arrays
564-
- An empty object can be created and used to push the values of array to respective property of the iteratee output
563+
- As the 2nd argument is either a function or property, the iteratee can be performed accordingly on the value of arrays
564+
- An empty object can be created and used to push the values of the array to the respective property of the iteratee output
565565

566566
```js copy
567567
function groupBy(values, iteratee) {
@@ -582,10 +582,10 @@ function groupBy(values, iteratee) {
582582

583583
---
584584

585-
### 18. Create a constructor function which allows its functions present on prototype to be accessed only by the objects created by calling it
585+
### 18. Create a constructor function that allows its functions present on the prototype to be accessed only by the objects created by calling it
586586

587-
- The list of objects created by the function can be kept in track using a collection object inside function
588-
- `Weakset` can be a prefered way to use as collection for objects created through it as the dereferencing the object helps in garbage collection
587+
- The list of objects created by the function can be kept track of using a collection object inside the function
588+
- `Weakset` can be a preferred way to use as a collection for objects created through it as the dereferencing of the object helps in garbage collection
589589
- A context validation within prototype method can be set if the object is created by the function itself or not
590590

591591
```js copy
@@ -612,7 +612,7 @@ ProtectedFunction.prototype.method.call(obj); // Incompatible object!
612612

613613
---
614614

615-
### 19. 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
615+
### 19. Design a utility on an array of objects where access can be made to the object using the index (as usual) and also from the primary key of the object
616616

617617
```js copy
618618
// Example
@@ -627,7 +627,7 @@ flexEmployees["Pai"]; // { name: 'Pai', id: '0' }
627627
flexEmployees["doe"]; // undefined
628628
```
629629

630-
- The access to the index happens for arrays by default and the Proxy can be setup to enable the fetching of object using primary key (any other key can also be coded)
630+
- The access to the index happens for arrays by default and the Proxy can be set to enable the fetching of objects using the primary key (any other key can also be coded)
631631

632632
```js copy
633633
const flexEmployees = new Proxy(employees, {
@@ -645,15 +645,15 @@ const flexEmployees = new Proxy(employees, {
645645

646646
---
647647

648-
### 20. Write a function which receives an object and returns a true if the object has circular reference
648+
### 20. Write a function that receives an object and returns a true if the object has a circular reference
649649

650650
```js copy
651651
// Example
652652
var circularReferenceObj = { data: 123 };
653653
circularReferenceObj.myself = circularReferenceObj;
654654
```
655655

656-
- Stringification of an object having circular references will throw error
656+
- Stringification of an object having circular references will throw an error
657657

658658
```js copy
659659
function doesObjectHaveCircularRef(obj) {
@@ -672,11 +672,11 @@ function doesObjectHaveCircularRef(obj) {
672672

673673
---
674674

675-
### 21. Write a code which can eliminate circular references in an object (Cyclic reference in an object)
675+
### 21. Write a code that can eliminate circular references in an object (Cyclic reference in an object)
676676

677-
- Circular / cyclic reference exists when the object property value forms a cycle
677+
- Circular/cyclic reference exists when the object property value forms a cycle
678678
- The circular references can be eliminated by passing a function to take care of circular references during stringification
679-
- The circular references can be also be eliminated by setting the such property value to null on the object itself
679+
- The circular references can also be eliminated by setting such property value to null on the object itself
680680

681681
```js copy
682682
const getCircularReplacer = () => {
@@ -716,14 +716,14 @@ function removeCircularRef(obj) {
716716

717717
**Notes**
718718

719-
`circularReferenceObj` is assumed to be an object with cyclic reference
719+
`circularReferenceObj` is assumed to be an object with a cyclic reference
720720

721721
---
722722

723723
### 22. Provide an object on which a value can be set to nested property even if it does not exist.
724724

725725
- The nested object can be accessed only if all the nested properties are defined on the object
726-
- A proxy can designed to create such nested object properties on demand whenever such non existent property is requested and attempted to set with value
726+
- A proxy can designed to create such nested object properties on demand whenever such non-existent property is requested and attempted to set with value
727727
- `get` trap of proxy can be used to create the objects dynamically and set the value
728728

729729
```js copy

0 commit comments

Comments
 (0)