aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Jacoby <jacoby.david@gmail.com>2020-10-01 18:24:29 -0400
committerDave Jacoby <jacoby.david@gmail.com>2020-10-01 18:24:29 -0400
commit70a60ae93a5ac9cef7380bc42a1d8581e3ef790b (patch)
treefdf8aece9f6a28f440631caa42f7edc81c7a0be3
parent6bd388f2116e5a366d242ea9f7d88411f0b3f280 (diff)
downloadperlweeklychallenge-club-70a60ae93a5ac9cef7380bc42a1d8581e3ef790b.tar.gz
perlweeklychallenge-club-70a60ae93a5ac9cef7380bc42a1d8581e3ef790b.tar.bz2
perlweeklychallenge-club-70a60ae93a5ac9cef7380bc42a1d8581e3ef790b.zip
JS and Blog
-rw-r--r--challenge-080/dave-jacoby/blog.txt1
-rwxr-xr-xchallenge-080/dave-jacoby/node/ch-1.js25
-rwxr-xr-xchallenge-080/dave-jacoby/node/ch-2.js22
3 files changed, 48 insertions, 0 deletions
diff --git a/challenge-080/dave-jacoby/blog.txt b/challenge-080/dave-jacoby/blog.txt
new file mode 100644
index 0000000000..95ae4e56fd
--- /dev/null
+++ b/challenge-080/dave-jacoby/blog.txt
@@ -0,0 +1 @@
+https://jacoby.github.io/2020/09/30/challenge-80.html
diff --git a/challenge-080/dave-jacoby/node/ch-1.js b/challenge-080/dave-jacoby/node/ch-1.js
new file mode 100755
index 0000000000..6e23ec8521
--- /dev/null
+++ b/challenge-080/dave-jacoby/node/ch-1.js
@@ -0,0 +1,25 @@
+"use strict"
+
+console.log( spnm( [5, 2, -2, 0 ] ));
+console.log( spnm( [1, 8, -1 ] ));
+console.log( spnm( [2, 0, -1 ] ));
+console.log( spnm( Array(12).fill().map((n, i) => 1 + i) ));
+
+function spnm ( array ) {
+ let list = array.filter( i => i > 0 );
+ let max = 1 + Math.max(...list);
+ let range = Array(max).fill().map((n, i) => 1 + i) ;
+ let hash = {};
+
+ for ( let i in list ) {
+ let n = list[i];
+ hash[n]=1;
+ }
+
+ for ( let i in range ) {
+ let n = range[i];
+ if ( !hash[n] ) { return n }
+ }
+ return -1
+}
+
diff --git a/challenge-080/dave-jacoby/node/ch-2.js b/challenge-080/dave-jacoby/node/ch-2.js
new file mode 100755
index 0000000000..a47fe0eb2b
--- /dev/null
+++ b/challenge-080/dave-jacoby/node/ch-2.js
@@ -0,0 +1,22 @@
+"use strict"
+
+console.log( candy_count( [1, 2, 2] ) );
+console.log( candy_count( [1, 4, 3, 2] ) );
+
+
+function candy_count( candidates ) {
+ let total = 0;
+ console.log( candidates );
+ for ( let i in candidates ) {
+ i = parseInt(i); // string by default
+ let v = candidates[i];
+ let prev = candidates[i-1] || 0;
+ let next = candidates[i+1] || 0;
+ total ++;
+ if ( v > prev && prev != 0 ) { total ++ }
+ if ( v > next && next != 0 ) { total ++ }
+ }
+ return total;
+}
+
+