cs142/project3/node_modules/cli/examples/sort.js

18 lines
428 B
JavaScript
Raw Normal View History

2020-08-01 22:26:11 +00:00
#!/usr/bin/env node
var cli = require('cli');
var options = cli.parse({
numeric: ['n', 'Compare using a numeric sort'],
reverse: ['r', 'Reverse the results']
});
cli.withStdinLines(function (lines, newline) {
lines.sort(!options.numeric ? null : function (a, b) {
return parseInt(a) > parseInt(b);
});
if (options.reverse) {
lines.reverse();
}
this.output(lines.join(newline));
});