-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubmit.js
More file actions
126 lines (84 loc) · 3.56 KB
/
Submit.js
File metadata and controls
126 lines (84 loc) · 3.56 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
function calculateTax(income, expenses) {
if (income >= 0 && income >= expenses && expenses >= 0) return (income - expenses) * 0.2;
else return "Invalid Input";
}
function sendNotification(email) {
if (typeof email === 'string' && email.includes('@') && email[0] !== '@' && email[email.length - 1] !== '@') {
const n = email.indexOf('@');
const userName = email.slice(0, n);
const domainName = email.slice(n + 1);
return `${userName} sent you an email from ${domainName}`;
} else return "Invalid Email";
}
function checkDigitsInName(name) {
if (typeof name === 'string') {
const number = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
const nameArr = name.split('');
let bulName = false;
for (const num of number) {
if (nameArr.includes(num)) {
bulName = true;
break;
}
} return bulName;
} else return "Invalid Input";
}
function calculateFinalScore(obj) {
if (typeof obj === 'object' &&
!Array.isArray(obj) &&
typeof obj.name === 'string' &&
typeof obj.testScore === 'number' &&
obj.testScore <= 50 &&
typeof obj.schoolGrade === 'number' &&
obj.schoolGrade <= 30 &&
typeof obj.isFFamily === 'boolean' &&
!isNaN(obj.schoolGrade) &&
!isNaN(obj.schoolGrade)
) {
const score = obj.isFFamily ? obj.testScore + obj.schoolGrade + 20 : obj.testScore + obj.schoolGrade;
return score >= 80 ? true : false;
} else return 'Invalid Input';
}
function waitingTime(waitingTimes, serialNumber) {
if (Array.isArray(waitingTimes) &&
typeof serialNumber === 'number' &&
!isNaN(serialNumber) &&
serialNumber > waitingTime.length
) {
const avgTime = waitingTimes.reduce((a, b) => a + b) / waitingTimes.length;
const remindPerson = serialNumber - waitingTimes.length - 1;
return remindPerson * Math.round(avgTime);
} else return 'Invalid Input ';
}
// !###################################################################################
console.log(calculateTax(10000, 3000));
console.log(calculateTax(34000, 1753));
console.log(calculateTax(5000, 1500));
console.log(calculateTax(7000, 7000));
console.log(calculateTax(-5000, 2000));
console.log(calculateTax(6000, -1500));
// ##############################
console.log(sendNotification('zihad@gmail.com'));
console.log(sendNotification('farhan34@yahoo.com'));
console.log(sendNotification('nadim.naem5@outlook.com'));
console.log(sendNotification('fahim234.hotmail.com'));
console.log(sendNotification('sadia8icloud.com'));
// ##############################
console.log(checkDigitsInName("Raj123"))
console.log(checkDigitsInName("Suman"))
console.log(checkDigitsInName("Name2024"))
console.log(checkDigitsInName("!@#"))
console.log(checkDigitsInName(["Raj"]));
// ##############################
console.log(calculateFinalScore({ name: "Rajib", testScore: 45, schoolGrade: 25, isFFamily: true }));
console.log(calculateFinalScore({ name: "Rajib", testScore: 45, schoolGrade: 25, isFFamily: false }));
console.log(calculateFinalScore("hello"));
console.log(calculateFinalScore({ name: "Rajib", testScore: 15, schoolGrade: 25, isFFamily: true }));
// ##############################
console.log(waitingTime([3, 5, 7, 11, 6], 10))
console.log(waitingTime([13, 2], 6))
console.log(waitingTime([13, 2, 6, 7, 10], 6))
console.log(waitingTime([6], 4))
console.log(waitingTime(7, 10))
console.log(waitingTime("[6,2]", 9))
console.log(waitingTime([7, 8, 3, 4, 5], "9"))