Skip to content

Instantly share code, notes, and snippets.

@brianloveswords
Last active August 29, 2015 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianloveswords/8698035 to your computer and use it in GitHub Desktop.
Save brianloveswords/8698035 to your computer and use it in GitHub Desktop.
function altcaps(words) {
const letters = words.toString('utf8')
const methods = ['Upper', 'Lower']
var idx = 0
var midx = (Math.random() * 100)|0
var newstring = ''
var letter
for (; idx < letters.length; idx++) {
letter = letters[idx]
newstring += (letter.match(/\s/))
? letter
: letter['to' + methods[midx++ % 2] + 'Case']()
}
return newstring
}
if (!module.parent) {
const fs = require('fs')
const path = require('path')
const swords = fs.readFileSync(path.join(__dirname, 'inspirational-quote.txt'))
console.log(altcaps(swords))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment