-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday13.js
51 lines (43 loc) · 979 Bytes
/
day13.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
// program to generate range of numbers and characters
function* iterate(a, b) {
for (let i = a; i <= b; i += 1) {
yield i;
}
}
function range(a, b) {
if (typeof a === "string") {
let result = [...iterate(a.charCodeAt(), b.charCodeAt())].map((n) =>
String.fromCharCode(n)
);
console.log(result);
} else {
let result = [...iterate(a, b)];
console.log(result);
}
}
range(1, 5);
range("A", "G");
// program to perform function overloading
function sum() {
// if no argument
if (arguments.length == 0) {
console.log("You have not passed any argument");
}
// if only one argument
else if (arguments.length == 1) {
console.log("Pass at least two arguments");
}
// multiple arguments
else {
let result = 0;
let length = arguments.length;
for (i = 0; i < length; i++) {
result = result + arguments[i];
}
console.log(result);
}
}
sum();
sum(5);
sum(5, 9);
sum(1, 2, 3, 4, 5, 6, 7, 8, 9);