UNPKG

565 BJavaScriptView Raw
1// sanity check command-line arguments
2if (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
9var strings = process.argv.slice(2);
10
11var lengths = [];
12
13// populate the lengths array with the length of each string
14for (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
19var json = JSON.stringify(lengths);
20
21console.log(json);
\No newline at end of file