Skip to content

Commit

Permalink
added commander and the option to only reverse the characters in words
Browse files Browse the repository at this point in the history
  • Loading branch information
SomeKittens committed May 13, 2014
1 parent 33ed1fd commit 289629e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
31 changes: 23 additions & 8 deletions bin/strrev
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,26 @@

'use strict';

var toReverse = process.argv
.slice(2)
.join(' ')
.split('')
.reverse()
.join('');

console.log(toReverse);
var program = require('commander')
, version = require('../package.json').version;

program
.version(version)
.option('-w, --words', 'Reverse the order of the words')
// TODO: .option('Reverse the letters in the words, but not the entire string')
.parse(process.argv);

var toReverse = program.args
, reversed;

if (program.words) {
reversed = [];
toReverse.forEach(function(word) {
reversed.push(word.split('').reverse().join(''));
});
reversed = reversed.join(' ');
} else {
reversed = toReverse.join(' ').split('').reverse().join('');
}

console.log(reversed);
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "interview",
"version": "0.0.7",
"version": "0.0.8",
"description": "A collection of command line tools for snarky answers to generic interview questions",
"main": "bin/fizzbuzz",
"bin": {
Expand Down

0 comments on commit 289629e

Please sign in to comment.