aboutsummaryrefslogtreecommitdiff
path: root/challenge-207/roger-bell-west/javascript/ch-2.js
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-207/roger-bell-west/javascript/ch-2.js')
-rwxr-xr-xchallenge-207/roger-bell-west/javascript/ch-2.js29
1 files changed, 29 insertions, 0 deletions
diff --git a/challenge-207/roger-bell-west/javascript/ch-2.js b/challenge-207/roger-bell-west/javascript/ch-2.js
new file mode 100755
index 0000000000..c18eeb7ed6
--- /dev/null
+++ b/challenge-207/roger-bell-west/javascript/ch-2.js
@@ -0,0 +1,29 @@
+#! /usr/bin/node
+
+"use strict"
+
+function h_index(c0) {
+ let c = c0.sort(function(a, b) {
+ return b-a;
+ });
+ let h = 0;
+ c.forEach((x, i) => {
+ if (i + 1 <= x) {
+ h = i + 1;
+ }
+ });
+ return h;
+}
+
+if (h_index([10, 8, 5, 4, 3]) == 4) {
+ process.stdout.write("Pass");
+} else {
+ process.stdout.write("FAIL");
+}
+process.stdout.write(" ");
+if (h_index([25, 8, 5, 3, 3]) == 3) {
+ process.stdout.write("Pass");
+} else {
+ process.stdout.write("FAIL");
+}
+process.stdout.write("\n");