diff options
| author | David Ferrone <zapwai@gmail.com> | 2024-03-15 11:21:15 -0400 |
|---|---|---|
| committer | David Ferrone <zapwai@gmail.com> | 2024-03-15 11:21:15 -0400 |
| commit | 60c68b3209b3c09d3cbd29b4ef33080546a43fbd (patch) | |
| tree | 48d43fa4f9c8ea2492e7ab11146b7df7bb1a1679 /challenge-006/zapwai/javascript | |
| parent | 2a68a16c1d8727b183d85c88f31ae6cec6a869b1 (diff) | |
| download | perlweeklychallenge-club-60c68b3209b3c09d3cbd29b4ef33080546a43fbd.tar.gz perlweeklychallenge-club-60c68b3209b3c09d3cbd29b4ef33080546a43fbd.tar.bz2 perlweeklychallenge-club-60c68b3209b3c09d3cbd29b4ef33080546a43fbd.zip | |
Weekly Challenge Blast from the Past
Diffstat (limited to 'challenge-006/zapwai/javascript')
| -rw-r--r-- | challenge-006/zapwai/javascript/ch-1.js | 41 | ||||
| -rw-r--r-- | challenge-006/zapwai/javascript/ch-2.js | 10 |
2 files changed, 51 insertions, 0 deletions
diff --git a/challenge-006/zapwai/javascript/ch-1.js b/challenge-006/zapwai/javascript/ch-1.js new file mode 100644 index 0000000000..769640f83a --- /dev/null +++ b/challenge-006/zapwai/javascript/ch-1.js @@ -0,0 +1,41 @@ +let list = [1,2,3,4,9,10,14,15,16]; +proc(list); + +function proc(list) { + console.log("Input:", list); + let output = ""; + + let init_flag = false; + let cont_flag = false; + + for (let i = 0; i < -1 + list.length; i++) { + let diff = list[i+1] - list[i]; + if (init_flag && cont_flag) { + if (diff != 1) { + init_flag = false; + cont_flag = false; + output += "-" + list[i]; + } + } else if (init_flag) { + if (diff == 1) + cont_flag = true; + else { + init_flag = false; + output += "," + list[i]; + } + } else { + if (i != 0) + output += ","; + output += list[i]; + if (diff == 1) + init_flag = true; + } + } + if (init_flag && cont_flag) + output += "-"; + else + output += ","; + output += list[list.length - 1]; + console.log("Output:", output); +} + diff --git a/challenge-006/zapwai/javascript/ch-2.js b/challenge-006/zapwai/javascript/ch-2.js new file mode 100644 index 0000000000..1532859946 --- /dev/null +++ b/challenge-006/zapwai/javascript/ch-2.js @@ -0,0 +1,10 @@ +Decimal.set({ precision: 35 }); +const x = new Decimal("163"); +const pi = new Decimal("3.141592653589793238462643383279502884197169"); +const r = pi.times(x.sqrt()); +const e = new Decimal("2.7182818284590452353602874713526624977572"); +const result = e.pow(r); +console.log(result.toString()); + +// Add this line to the html file to include the Decimal library: +// <script src="https://cdnjs.cloudflare.com/ajax/libs/decimal.js/10.3.1/decimal.min.js"></script> |
