Skip to content

Commit

Permalink
fix(node4): fixed build for node 4/5
Browse files Browse the repository at this point in the history
  • Loading branch information
spudly committed Aug 5, 2016
1 parent 8a41fa2 commit 49539f7
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ const dictionary = require('./dictionary');
const isUpperCase = char => char.toUpperCase() === char;

const talkLikeAPirate = str => str.replace(/[\w']+/ig, match => {
let replacement = dictionary[match.toLowerCase()];
const replacement = dictionary[match.toLowerCase()];

if (!replacement) {
return match;
}

if (Array.isArray(replacement)) {
// get array element at random
replacement = replacement[Math.floor(Math.random() * replacement.length)];
return replacement[Math.floor(Math.random() * replacement.length)];
}

if (isUpperCase(match[0])) {
replacement = replacement[0].toUpperCase() + replacement.slice(1);
return replacement[0].toUpperCase() + replacement.slice(1);
}

return replacement;
Expand Down

0 comments on commit 49539f7

Please sign in to comment.