blob: 847777ec00fb6e4cfba634b8c6cc9e1a6cdd5acc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
#!/usr/local/bin/node
//
// See https://theweeklychallenge.org/blog/perl-weekly-challenge-001
//
//
// Run as: node ch-1.js < input-file
//
//
// Read STDIN. Split on newlines, filter out empty lines, then call "main".
//
require ("fs")
. readFileSync (0) // Read all.
. toString () // Turn it into a string.
. split ("\n") // Split on newlines.
. filter (_ => _ . length) // Filter out empty lines.
. map (_ => {
//
// replace() returns the modified string, so we do a separate
// match to get the actual count of the number of 'e's
//
count = [... _ . matchAll (/e/g)] . length;
//
// Do the replacement, and print the results. Print also
// the number of times 'e' appears.
//
process . stdout . write (_ . replace (/e/g, "E") + "\n" + count + "\n")
})
;
|