-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathday11.js
171 lines (140 loc) · 4.66 KB
/
day11.js
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import {countriesData} from './data/countries_data.js'
const users = [
{
name:'Brook',
scores:75,
skills:['HTM', 'CSS', 'JS'],
age:16
},
{
name:'Alex',
scores:80,
skills:['HTM', 'CSS', 'JS'],
age:18
},
{
name:'David',
scores:75,
skills:['HTM', 'CSS'],
age:22
},
{
name:'John',
scores:85,
skills:['HTML'],
age:25
},
{
name:'Sara',
scores:95,
skills:['HTM', 'CSS', 'JS'],
age: 26
},
{
name:'Martha',
scores:80,
skills:['HTM', 'CSS', 'JS'],
age:18
},
{
name:'Thomas',
scores:90,
skills:['HTM', 'CSS', 'JS'],
age:20
}
]
/* 1- Destructure and assign the elements of constants array to e, pi, gravity,
humanBodyTemp, waterBoilingTemp. */
let [e,pi,gravity,humanBodyTemp,waterBoilingTemp]=[Math.E.toFixed(2),Math.PI.toFixed(2),9.8,36, 100]
//console.log(e,pi,gravity,humanBodyTemp,waterBoilingTemp)
// 2-Destructure and assign the elements of countries array to fin, est, sw, den, nor
const countries = ['Finland', 'Estonia', 'Sweden', 'Denmark', 'Norway']
let [fin,est,sw,den,nor]=countries
//console.log(' fin:'+fin+ ' est:'+est+ ' sw:'+sw+ ' den:'+den+ ' nor:'+nor);
// 3-Destructure the rectangle object by its properties or keys.
const rectangle = {
width: 20,
height: 10,
area: 200,
perimeter: 60
}
const {width,height,area,perimeter}=rectangle
//console.log( typeof perimeter)
//Exercises: Level 2
//1- Iterate through the users array and get all the keys of the object using destructuring
for(const {name,scores,skills,age} of users){
// console.log(`name: ${name} scores:${scores} skills:${skills} age:${age}`);
}
//2- Find the persons who have less than two skills
console.log('People who have less than 2 skills: ');
for(const {name,scores,skills,age} of users){
// /console.log(`${name}: ${skills}`)
if(skills.length<=2)
console.log(name);
}
// Exercises: Level 3
//1-Destructure the countries object print name, capital, population and languages of all countries
for(let {name,capital,population,languages} of countriesData){
//console.log(`Name:${name}\nCapital:${capital}\nPopulation:${population}\nLanguages:${languages}`);
}
/*
2-A junior developer structure student name, skills and score in array of arrays which may not easy
to read. Destructure the following array name to name, skills array to skills, scores array to scores, JavaScript score to jsScore and React score to reactScore variable in one line. */
const student = ['David', ['HTM', 'CSS', 'JS', 'React'], [98, 85, 90, 95]]
let[name,skills,scores] =student
//console.log([...student] )
//console.log(skills)
//console.log(scores[0])
//console.log(reactScore);
//console.log(name, skills, jsScore, reactScore)
// 3- Write a function called convertArrayToObject which can convert the array to a structure object
const students = [
['David', ['HTML', 'CSS', 'JS', 'React'], [98, 85, 90, 95]],
['John', ['HTML', 'CSS', 'JS', 'React'], [85, 80, 85, 80]]
]
function convertArrayToObject(){
let arrayOfStudentInfos=[]
for(const [name,skills,scores ]of students){
arrayOfStudentInfos.push({
name:name,
skills:skills,
scores:scores
})
}
return arrayOfStudentInfos
}
//console.log(convertArrayToObject())
// 4-Copy the student object to newStudent without mutating the original object.
// In the new object add the following ?
const studentSS = {
name: 'David',
age: 25,
skills: {
frontEnd: [
{ skill: 'HTML', level: 10 },
{ skill: 'CSS', level: 8 },
{ skill: 'JS', level: 8 },
{ skill: 'React', level: 9 }
],
backEnd: [
{ skill: 'Node',level: 7 },
{ skill: 'GraphQL', level: 8 },
],
dataBase:[
{ skill: 'MongoDB', level: 7.5 },
],
dataScience:['Python', 'R', 'D3.js']
}
}
// -Add Bootstrap with level 8 to the front end skill sets
let newStudent={...studentSS,skills:{...studentSS.skills,frontEnd:[...studentSS.skills.frontEnd,{skill:'Bootstrap',level:8}]}}
console.log(newStudent);
// -Add Express with level 9 to the back end skill sets
newStudent={...studentSS,skills:{...newStudent.skills,backEnd:[...newStudent.skills.backEnd, {skill:'Express',level:9}]}}
console.log(newStudent);
// -Add SQL with level 8 to the data base skill sets
newStudent={...studentSS,skills:{...newStudent.skills,dataBase:[...newStudent.skills.dataBase, {skill:'SQL',level:8}]}}
console.log(newStudent);
//Add SQL without level to the data science skill sets
newStudent={...studentSS,skills:{...newStudent.skills,dataScience:[...newStudent.skills.dataScience,'SQL']}}
console.log(newStudent);