-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay34.js
More file actions
152 lines (87 loc) · 2.72 KB
/
Day34.js
File metadata and controls
152 lines (87 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
//This keyword & Function Methods [Call, Apply, Bind]!
// let person = { name: "John" };
// function greet() {
// console.log("Hello, " + this.name);
// }
// let greetPerson = greet.bind(person);
// greetPerson();
//Problem Statement:
// Create a simple JavaScript object called student with properties: name, age, and course.
// Then, use the JSON.stringify() method to convert the object into a JSON string and log it to the console.
// Example Input:
// let student = {
// name: "Alice",
// age: 22,
// course: "Computer Science"
// };
// Expected Output:
// {
// "name": "Alice",
// "age": 22,
// "course": "Computer Science"
// }
// let student =
// {
// name: "Alice",
// age: 22,
// course: "Computer Science"
// };
// console.log(JSON.stringify(student));
//Problem Statement:
// Write a function called multiplyNumbers that accepts two
// numbers as arguments and uses the apply() method to multiply them.
// The function should return the product.
// function multiplyNumbers(a, b)
// {
// let help =
// {
// multiply: function(x, y)
// {
// return x*y;
// }
// };
// return help.multiply.apply(null, [a, b]);
// }
// console.log(multiplyNumbers(5, 4));
//Problem Statement:
//Write a function deepClone(obj) that creates a deep copy of a given object
// using JSON.stringify() and JSON.parse(). The function should ensure that
// modifying the cloned object does not affect the original object.
// Example Input:
// { name: "Alice", hobbies: ["reading", "traveling"] }
// Example Output (After modifying the clone):
// Original: { name: "Alice", hobbies: ["reading", "traveling"] }
// Clone: { name: "Alice", hobbies: ["reading", "traveling", "coding"] }
// let obj =
// {
// name: "Alice",
// hobbies: ["reading", "traveling"]
// };
// let nObj = JSON.parse(JSON.stringify(obj));
// nObj.hobbies.push("coding");
// console.log(obj);
// console.log(nObj);
// const original = { details: { year: 1995 } };
// const deepCopy = JSON.parse(JSON.stringify(original));
// deepCopy.details.year = 2023;
// console.log(original.details.year); // 1995 (original remains unchanged)
// let rest1 = {
// food: ['south Indian','North Indian', 'chinese']
// }
// let rest2 = {
// food: ['south Indian','North Indian', 'chinese','Italian']
// }
// let rest3 = {
// food: ['south Indian','North Indian',]
// }
// let rest4 = {
// food: ['south Indian','North Indian','Continental','Mughlai']
// }
// function foodDelivery()
// {
// console.log(this.food);
// }
// foodDelivery.call(rest1);
// foodDelivery.call(rest2);
// foodDelivery.call(rest3);
// foodDelivery.call(rest4);