-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidator.js
More file actions
26 lines (25 loc) · 952 Bytes
/
validator.js
File metadata and controls
26 lines (25 loc) · 952 Bytes
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
module.exports.validateSimple =(principal, rate, time) => {
if (typeof principal !== 'number' || principal <= 0) {
return 'Principal must be a POSITIVE NUMBER.';
}
if (typeof rate !== 'number' || rate <= 0) {
return 'Rate must be a POSITIVE NUMBER.';
}
if (typeof time !== 'number' || time <= 0) {
return 'Time must be a POSITIVE NUMBER.';
}
}
module.exports.validateCompound = (principal, rate, time, frequency) => {
if (typeof principal !== 'number' || principal <= 0) {
return 'Principal must be a POSITIVE NUMBER.';
}
if (typeof rate !== 'number' || rate <= 0) {
return 'Rate must be a POSITIVE NUMBER.';
}
if (typeof time !== 'number' || time <= 0) {
return 'Time must be a POSITIVE NUMBER.';
}
if (typeof frequency !== 'number' || frequency <= 0 || !Number.isInteger(frequency)) {
return 'Frequency must be a POSITIVE INTEGER.';
}
}