1 | // sanity check command-line arguments
|
2 | if (process.argv.length == 2) {
|
3 | return console.log('Please provide a list of strings');
|
4 | }
|
5 |
|
6 | // Array#slice() returns a new array starting from the
|
7 | // specified index, so we can trim argv to just the
|
8 | // additional arguments
|
9 | var strings = process.argv.slice(2);
|
10 |
|
11 | var lengths = [];
|
12 |
|
13 | // populate the lengths array with the length of each string
|
14 | for (var i = 0; i < strings.length; i++) {
|
15 | lengths[i] = strings[i].length;
|
16 | }
|
17 |
|
18 | // print out a JSON-encoded version of the array
|
19 | var json = JSON.stringify(lengths);
|
20 |
|
21 | console.log(json); |
\ | No newline at end of file |