forked from zero-to-mastery/JS_Fun_Practice
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolutions.html
More file actions
179 lines (172 loc) · 4.15 KB
/
solutions.html
File metadata and controls
179 lines (172 loc) · 4.15 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<!DOCTYPE html>
<html>
<head><!--
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" />
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" />
<link rel="manifest" href="/site.webmanifest" />
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5" />
<meta name="msapplication-TileColor" content="#da532c" />
<meta name="theme-color" content="#ffffff" /> -->
<link rel="stylesheet" href="style.css" />
<title>Solutions</title>
</head>
<body>
<div class="header">
<h1>Solutions Part 1</h1>
<p>A selected few solutions to some of the exercies</p>
</div>
<div class= "container">
<dl>
<ol>
<li>
<dd>
<p> Write a function identity that takes an argument and returns that argument</p>
</dd>
<dt>
<code>const identity = function identity(x) {
return x
}
OR
const identity = (x) => x;
console.log(identity('Hello Slavo'));
console.log('---------------------');
</code>
</dt>
</li>
<li>
<dd>
<p> Write a binary function addb that takes two numbers and returns their sum</p>
</dd>
<dt>
<code> const addb = (a, b) => {
return a + b
}
console.log(addb(3, 4))
console.log('-----------------------')
</code>
</dt>
</li>
<li>
<dd>
<p> Write a binary function subb that takes two numbers and returns their difference</p>
</dd>
<dt>
<code>
const subb = (a, b) => {
return a - b
}
console.log(subb(3, 4));
console.log('----------------------')
</code>
</dt>
</li>
<li>
<dd>
<p>Write a binary function mulb that takes two numbers and returns their product</p>
</dd>
<dt>
<code>
const mulb = (a, b) => {
return a * b
}
console.log(mulb(3, 4))
console.log('-------------------')
</code>
</dt>
</li>
<li>
<dd>
<p>Write a binary function minb that takes two numbers and returns the smaller one</p>
</dd>
<dt>
<code>
const minb = (a, b) => {
return a < b
? a
: b
}
console.log(minb(3, 4))
console.log('--------------------')
</code>
</dt>
</li>
<li>
<dd>
<p>Write a binary function maxb that takes two numbers and returns the larger one</p>
</dd>
<dt>
<code>
const maxb = (a, b) => {
return a > b
? a
: b
}
console.log(maxb(3, 4));
console.log('---------------------------')
</code>
</dt>
</li>
<li>
<dd>
<p>Write a function add that is generalized for any amount of arguments</p>
</dd>
<dt>
<code>
const add = (...nums) => {
return nums.reduce((a, b) => a + b)
}
console.log("add " + add(1, 2, 4, 5))
console.log('-----------------');
</code>
</dt>
</li>
<li>
<dd>
<p>Write a function sub that is generalized for any amount of arguments</p>
</dd>
<dt>
<code>
const sub = (...nums) => {
return nums.reduce((a, b) => a - b)
}
console.log(sub(1, 2, 4))
console.log('-----------------');
</code>
</dt>
</li>
<li>
<dd>
<p>Write a function mul that is generalized for any amount of arguments</p>
</dd>
<dt>
<code>
const mul = (...nums) => {
return nums.reduce((a, b) => a * b)
}
console.log(mul(1, 2, 4))
console.log('-----------------');
</code>
</dt>
</li>
<li>
<dd>
<p>Write a function min that is generalized for any amount of arguments</p>
</dd>
<dt>
<code>
const min = (...nums) => {
return nums.reduce((a, b) => a < b
? a
: b);
}
console.log(min(7, 2, 1, 35, -1, -9, 44, 67))
console.log('-----------------');
</code>
</dt>
</li>
</ol>
</dl>
</div>
</body>
</html>