Skip to content

Instantly share code, notes, and snippets.

@TylerL-uxai
Forked from anonymous/bonfire-pig-latin.js
Created December 12, 2015 00:38

Revisions

  1. @invalid-email-address Anonymous created this gist Dec 12, 2015.
    17 changes: 17 additions & 0 deletions bonfire-pig-latin.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    // Bonfire: Pig Latin
    // Author: @tylerl-uxai
    // Challenge: http://www.freecodecamp.com/challenges/bonfire-pig-latin
    // Learn to Code at Free Code Camp (www.freecodecamp.com)

    function translate(str) {
    var regex = /[aeiou]/gi;
    if (str[0].match(regex)){
    return str + "way";
    } else if (str[1].match(regex)){
    return str.slice(1) + str.charAt(0) + "ay";
    } else {
    return str.slice(2)+str.charAt(0)+str.charAt(1)+"ay";
    }
    }

    translate("consonant");