diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-09-16 20:22:45 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-16 20:22:45 +0100 |
| commit | 6ba96d45227883a88bec4e91870d341e097ca8d1 (patch) | |
| tree | 77e38d414aaea777fa5f89cdd1c3837c8f759ad6 /challenge-287/zapwai/javascript/ch-2.js | |
| parent | 7211ba649cbe1119acfa16d7fa942f70e3b2759d (diff) | |
| parent | 3e3e9530a265cb3f549a3556bb78ffdcb1023650 (diff) | |
| download | perlweeklychallenge-club-6ba96d45227883a88bec4e91870d341e097ca8d1.tar.gz perlweeklychallenge-club-6ba96d45227883a88bec4e91870d341e097ca8d1.tar.bz2 perlweeklychallenge-club-6ba96d45227883a88bec4e91870d341e097ca8d1.zip | |
Merge pull request #10852 from zapwai/branch-for-287
Week 287
Diffstat (limited to 'challenge-287/zapwai/javascript/ch-2.js')
| -rw-r--r-- | challenge-287/zapwai/javascript/ch-2.js | 39 |
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); +} |
