Last active
August 29, 2015 13:55
-
-
Save brianloveswords/8698035 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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