Skip to content

Commit faffe2b

Browse files
committed
My coersion solution
1 parent d0e6743 commit faffe2b

File tree

1 file changed

+34
-0
lines changed
  • types-exercises/coercion

1 file changed

+34
-0
lines changed

types-exercises/coercion/ex.js

+34
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,39 @@
11
// TODO: write the validation functions
2+
function isValidName(name) {
3+
return typeof name === "string" && name !== "" && nonWhiteSpaceOfAtLeast3Chars(name)
24

5+
function nonWhiteSpaceOfAtLeast3Chars(name) {
6+
return name.length >= 3 && name[0] !== " " && name[1] !== " " && name[2] !== " "
7+
}
8+
}
9+
10+
function hoursAttended(attend, length) {
11+
return isStringOrNumber(attend) &&
12+
isStringOrNumber(length) &&
13+
canBeANumber(attend) &&
14+
canBeANumber(length) &&
15+
isZeroOrHigher(attend) &&
16+
isZeroOrHigher(length) &&
17+
isWholeNumber(attend) &&
18+
isWholeNumber(length) &&
19+
(Number(attend) <= Number(length))
20+
21+
function isStringOrNumber(num) {
22+
return typeof num == "string" || typeof num == "number"
23+
}
24+
25+
function canBeANumber(num) {
26+
return Number(num) !== NaN && num !== ""
27+
}
28+
29+
function isZeroOrHigher(num) {
30+
return Number(num) >= 0
31+
}
32+
33+
function isWholeNumber(num) {
34+
return Number(num) % 1 == 0
35+
}
36+
}
337

438

539
// tests:

0 commit comments

Comments
 (0)