|
| 1 | +function calculateTax(income, expenses) { |
| 2 | + if (income >= 0 && income >= expenses && expenses >= 0) return (income - expenses) * 0.2; |
| 3 | + else return "Invalid Input"; |
| 4 | +} |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | +function sendNotification(email) { |
| 9 | + if (typeof email === 'string' && email.includes('@') && email[0] !== '@' && email[email.length - 1] !== '@') { |
| 10 | + const n = email.indexOf('@'); |
| 11 | + const userName = email.slice(0, n); |
| 12 | + const domainName = email.slice(n + 1); |
| 13 | + |
| 14 | + return `${userName} sent you an email from ${domainName}`; |
| 15 | + |
| 16 | + } else return "Invalid Email"; |
| 17 | +} |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | +function checkDigitsInName(name) { |
| 22 | + if (typeof name === 'string') { |
| 23 | + const number = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']; |
| 24 | + const nameArr = name.split(''); |
| 25 | + let bulName = false; |
| 26 | + |
| 27 | + for (const num of number) { |
| 28 | + if (nameArr.includes(num)) { |
| 29 | + bulName = true; |
| 30 | + break; |
| 31 | + } |
| 32 | + } return bulName; |
| 33 | + } else return "Invalid Input"; |
| 34 | +} |
| 35 | + |
| 36 | + |
| 37 | + |
| 38 | +function calculateFinalScore(obj) { |
| 39 | + if (typeof obj === 'object' && |
| 40 | + !Array.isArray(obj) && |
| 41 | + typeof obj.name === 'string' && |
| 42 | + typeof obj.testScore === 'number' && |
| 43 | + obj.testScore <= 50 && |
| 44 | + typeof obj.schoolGrade === 'number' && |
| 45 | + obj.schoolGrade <= 30 && |
| 46 | + typeof obj.isFFamily === 'boolean' && |
| 47 | + !isNaN(obj.schoolGrade) && |
| 48 | + !isNaN(obj.schoolGrade) |
| 49 | + ) { |
| 50 | + const score = obj.isFFamily ? obj.testScore + obj.schoolGrade + 20 : obj.testScore + obj.schoolGrade; |
| 51 | + return score >= 80 ? true : false; |
| 52 | + } else return 'Invalid Input'; |
| 53 | +} |
| 54 | + |
| 55 | + |
| 56 | + |
| 57 | +function waitingTime(waitingTimes, serialNumber) { |
| 58 | + if (Array.isArray(waitingTimes) && |
| 59 | + typeof serialNumber === 'number' && |
| 60 | + !isNaN(serialNumber) && |
| 61 | + serialNumber > waitingTime.length |
| 62 | + ) { |
| 63 | + const avgTime = waitingTimes.reduce((a, b) => a + b) / waitingTimes.length; |
| 64 | + const remindPerson = serialNumber - waitingTimes.length - 1; |
| 65 | + return remindPerson * Math.round(avgTime); |
| 66 | + |
| 67 | + } else return 'Invalid Input '; |
| 68 | +} |
| 69 | + |
| 70 | + |
| 71 | + |
| 72 | + |
| 73 | + |
| 74 | +// !################################################################################### |
| 75 | + |
| 76 | + |
| 77 | + |
| 78 | + |
| 79 | + |
| 80 | +console.log(calculateTax(10000, 3000)); |
| 81 | +console.log(calculateTax(34000, 1753)); |
| 82 | +console.log(calculateTax(5000, 1500)); |
| 83 | +console.log(calculateTax(7000, 7000)); |
| 84 | +console.log(calculateTax(-5000, 2000)); |
| 85 | +console.log(calculateTax(6000, -1500)); |
| 86 | + |
| 87 | + |
| 88 | +// ############################## |
| 89 | + |
| 90 | + |
| 91 | +console.log(sendNotification('zihad@gmail.com')); |
| 92 | +console.log(sendNotification('farhan34@yahoo.com')); |
| 93 | +console.log(sendNotification('nadim.naem5@outlook.com')); |
| 94 | +console.log(sendNotification('fahim234.hotmail.com')); |
| 95 | +console.log(sendNotification('sadia8icloud.com')); |
| 96 | + |
| 97 | + |
| 98 | +// ############################## |
| 99 | + |
| 100 | + |
| 101 | +console.log(checkDigitsInName("Raj123")) |
| 102 | +console.log(checkDigitsInName("Suman")) |
| 103 | +console.log(checkDigitsInName("Name2024")) |
| 104 | +console.log(checkDigitsInName("!@#")) |
| 105 | +console.log(checkDigitsInName(["Raj"])); |
| 106 | + |
| 107 | + |
| 108 | +// ############################## |
| 109 | + |
| 110 | + |
| 111 | +console.log(calculateFinalScore({ name: "Rajib", testScore: 45, schoolGrade: 25, isFFamily: true })); |
| 112 | +console.log(calculateFinalScore({ name: "Rajib", testScore: 45, schoolGrade: 25, isFFamily: false })); |
| 113 | +console.log(calculateFinalScore("hello")); |
| 114 | +console.log(calculateFinalScore({ name: "Rajib", testScore: 15, schoolGrade: 25, isFFamily: true })); |
| 115 | + |
| 116 | + |
| 117 | +// ############################## |
| 118 | + |
| 119 | + |
| 120 | +console.log(waitingTime([3, 5, 7, 11, 6], 10)) |
| 121 | +console.log(waitingTime([13, 2], 6)) |
| 122 | +console.log(waitingTime([13, 2, 6, 7, 10], 6)) |
| 123 | +console.log(waitingTime([6], 4)) |
| 124 | +console.log(waitingTime(7, 10)) |
| 125 | +console.log(waitingTime("[6,2]", 9)) |
| 126 | +console.log(waitingTime([7, 8, 3, 4, 5], "9")) |
0 commit comments