diff options
| -rw-r--r-- | challenge-097/abigail/node/ch-1.js | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/challenge-097/abigail/node/ch-1.js b/challenge-097/abigail/node/ch-1.js new file mode 100644 index 0000000000..0cba6f1a23 --- /dev/null +++ b/challenge-097/abigail/node/ch-1.js @@ -0,0 +1,50 @@ +#!/usr/local/bin/node + +// +// See ../README.md +// + +// +// Run as: node ch-1.js -s TIMES < input-file +// + +const NR_OF_LETTERS = 26 + +// +// Parse input +// +const argv = require ('yargs') +. option ('s', { + type: 'number', + }) +. demandOption ('s') +. argv; + +const shift = argv . s + +// +// Shift capital letters, by a given amount. +// +function shift_char (char, shift) { + if (char . match (/[A-Z]/)) { + let n = char . charCodeAt (0) - (shift % NR_OF_LETTERS) + if (n < 65) { + n = n + NR_OF_LETTERS + } + return String . fromCharCode (n) + } + else { + return char + } +} + + +// +// Iterate over the input, and shift characters +// +require ('readline') +. createInterface ({input: process . stdin}) +. on ('line', _ => console . log (_ . split ("") + . map (_ => shift_char (_, shift)) + . join (""))) +; |
