aboutsummaryrefslogtreecommitdiff
path: root/challenge-078/abigail/node/ch-2.js
diff options
context:
space:
mode:
author冯昶 <seaker@qq.com>2020-09-21 14:20:42 +0800
committer冯昶 <seaker@qq.com>2020-09-21 14:20:42 +0800
commitbca0c362c212fc0dadc5ed7d9a5e4fa1aece4bfb (patch)
tree877181cfde26b706346d3468269e4674d75da772 /challenge-078/abigail/node/ch-2.js
parentec09b571a6f2186fec8870a071a8d5d38596c850 (diff)
parent5ac16ac7e9826137e0da5597e954f4992c66205d (diff)
downloadperlweeklychallenge-club-bca0c362c212fc0dadc5ed7d9a5e4fa1aece4bfb.tar.gz
perlweeklychallenge-club-bca0c362c212fc0dadc5ed7d9a5e4fa1aece4bfb.tar.bz2
perlweeklychallenge-club-bca0c362c212fc0dadc5ed7d9a5e4fa1aece4bfb.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-078/abigail/node/ch-2.js')
-rw-r--r--challenge-078/abigail/node/ch-2.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/challenge-078/abigail/node/ch-2.js b/challenge-078/abigail/node/ch-2.js
new file mode 100644
index 0000000000..6d76c9aa91
--- /dev/null
+++ b/challenge-078/abigail/node/ch-2.js
@@ -0,0 +1,33 @@
+//
+// Exercise:
+//
+// You are given array @A containing positive numbers and @B containing
+// one or more indices from the array @A.
+// Write a script to left rotate @A so that the number at the first index
+// of @B becomes the first element in the array. Similary, left rotate @A
+// again so that the number at the second index of @B becomes the first
+// element in the array.
+//
+// We will be reading the arrays from STDIN -- @A is one the first
+// line, @B is on the second line.
+//
+
+//
+// Read two lines from STDIN, turn it into a string, strip off the
+// trailing newline (and any leading or trailing whitespace),
+// and then split in on spaces. Store the result into an arrays A and B.
+//
+let fs = require ("fs");
+let lines = fs . readFileSync (0) . toString () . split ("\n");
+let A = lines [0] . trim () . split (" ");
+let B = lines [1] . trim () . split (" ");
+
+
+//
+// Iterate over the array B, and print the slices of A.
+//
+for (let i = 0; i < B . length; i ++) {
+ let index = +B [i];
+ console . log (A . slice ( index) . join (" ") + " " +
+ A . slice (0, index) . join (" "));
+}