-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathas12.js
More file actions
142 lines (123 loc) · 3.99 KB
/
as12.js
File metadata and controls
142 lines (123 loc) · 3.99 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
// 1. Write a JavaScript program to map Employee Records according to Employee IDs.
// Employee: { id, name, salary }
// a) Print an array of all employee ids
// b) Print count of employees
// c) Print the name of the employee according to their id { key: value }
// d) Store the salaries of all employees in an array
// e) Calculate the average salary the company is paying to its employees
// Sample Input:
// "id": [ 67, 48, 29 ]
// "name": [ "Hitanshu", “Ninad”, “Amandeep” ]
// "salary": [ 75000, 82000, 98000 ]
// Output:
// [ 67, 48, 29 ]
// 3
// 67: Hitanshu
// 48: Ninad
// 29: Amandeep
// [ 75000, 82000, 98000 ]
// 85000
// const person = {
// "id": [ 67, 48, 29 ],
// "name": [ "Hitanshu", "Ninad", "Amandeep" ],
// "salary": [ 75000, 82000, 98000 ]
// }
// let sum = 0
// console.log(person.id);
// console.log(person.id.length);
// for(let i = 0; i<person.salary.length; i++){
// sum += person.salary[i];
// console.log(person.id[i], ":" , person.name[i]);
// }
// console.log(person.salary);
// console.log("Average Salary = ", sum/person.salary.length);
// 2. Write a program in JavaScript to map the student ids, names and scores.
// a) Add data for 3 students (use map functions)
// b) Get Student Names using map functions
// c) Delete Student Scores using map functions
// d) Display 1 parameter (only value), 2 parameters (value + key), and 3
// parameters (value + key + map) for the student
// Sample Input:
// "id": [ 1, 2, 3 ]
// "name": [ 'Hitanshu', 'Ninad', 'Amandeep' ]
// "scores": [ 90, 88, 92 ]
// Output:
// [ 'Hitanshu', 'Ninad', 'Amandeep' ]
// -----one parameter-----
// [ 1, 2, 3 ]
// [ 'Hitanshu', 'Ninad', 'Amandeep' ]
// [ 90, 88, 92 ]
// -----two parameter-----
// id 1, 2, 3
// name Hitanshu,Ninad,Amandeep
// scores 90,88,92
// -----three parameter-----
// id 1, 2, 3
// Map(3) {
// 'id' => [ 67, 48, 29 ],
// 'name' => [ 'Hitanshu', 'Ninad', 'Amandeep' ],
// 'scores' => [ 90, 88, 92 ]
// }
// name Hitanshu,Ninad,Amandeep
// Map(3) {
// 'id' => [ 1, 2, 3 ],
// 'name' => [ 'Hitanshu', 'Ninad', 'Amandeep' ],
// 'scores' => [ 90, 88, 92 ]
// }
// scores 90,88,92
// Map(3) {
// 'id' => [ 1, 2, 3 ],
// 'name' => [ 'Hitanshu', 'Ninad', 'Amandeep' ],
// 'scores' => [ 90, 88, 92 ]
// }
let studentData = {
id: [1, 2, 3],
name: ['Hitanshu', 'Ninad', 'Amandeep'],
scores: [90, 88, 92],
};
// a) Add data for 3 students (use map functions)
let studentMap = new Map();
studentMap.set('id', studentData.id.map((id) => id + 66));
studentMap.set('name', studentData.name);
studentMap.set('scores', studentData.scores);
// b) Get Student Names using map functions
let studentNames = studentMap.get('name');
// c) Delete Student Scores using map functions
studentMap.delete('scores');
// d) Display 1 parameter (only value), 2 parameters (value + key), and 3 parameters (value + key + map) for the student
// Sample Input:
// "id": [ 1, 2, 3 ]
// "name": [ 'Hitanshu', 'Ninad', 'Amandeep' ]
// "scores": [ 90, 88, 92 ]
// Output:
// [ 'Hitanshu', 'Ninad', 'Amandeep' ]
// -----one parameter-----
console.log("-----one parameter-----");
console.log(studentNames);
// [ 1, 2, 3 ]
// [ 'Hitanshu', 'Ninad', 'Amandeep' ]
// -----two parameter-----
console.log("-----two parameter-----");
console.log(`id ${studentData.id}`);
console.log(`name ${studentNames}`);
console.log("-----three parameter-----");
console.log(`id ${studentData.id}`);
console.log(studentMap);
console.log(`name ${studentNames}`);
console.log(studentMap.get('id'));
// 3. Write a JavaScript program to iterate over an array inputted by the user using
// mapping. Perform the square of all elements in the original array, store the
// squares in a new array and make a mapping for the squares and display it.
// Sample Input:
// [ 1, 2, 3, 4, 5 ]
// Explanation:
// Original Array = [ 1, 2, 3, 4, 5 ]
// New Array = [ 1, 4, 9, 16, 25 ]
// Mapping = squares => [ 1, 4, 9, 16, 25 ]
// Output:
// [ 1, 4, 9, 16, 25 ]
// const arr = [ 1, 2, 3, 4, 5 ]
// const newArr = arr.map((num)=>{
// return num*num
// })
// console.log(newArr);