aboutsummaryrefslogtreecommitdiff
path: root/challenge-287/zapwai/javascript/ch-2.js
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-287/zapwai/javascript/ch-2.js')
-rw-r--r--challenge-287/zapwai/javascript/ch-2.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/challenge-287/zapwai/javascript/ch-2.js b/challenge-287/zapwai/javascript/ch-2.js
new file mode 100644
index 0000000000..23e068bc82
--- /dev/null
+++ b/challenge-287/zapwai/javascript/ch-2.js
@@ -0,0 +1,39 @@
+let str = "1";
+proc(str);
+str = "56e10";
+proc(str);
+str = "2E32";
+proc(str);
+str = "a";
+proc(str);
+str = "1.2";
+proc(str);
+str = "1.2.6";
+proc(str);
+str = "3.142e10";
+proc(str);
+str = "3.142e42B";
+proc(str);
+
+function proc(str) {
+ console.log( "Input:", str);
+ let output = "False";
+ let p = str.split(".");
+ let dre = /^\d+$/
+ let dere = /^\d+e\d+$|^\d+E\d+$/;
+ let deere = /^\d+e\d+$|^\d+E\d+$/;
+ if (p.length == 1) {
+ if (dre.test(str)) {
+ output = "True";
+ } else if (dere.test(str)) {
+ output = "True";
+ }
+ } else if (p.length == 2) {
+ if (dre.test(p[0]) && dre.test(p[1])) {
+ output = "True";
+ } else if (dre.test(p[0]) && deere.test(p[1])) {
+ output = "True";
+ }
+ }
+ console.log("Output:", output);
+}