Skip to content

Instantly share code, notes, and snippets.

View johncmunson's full-sized avatar

John Munson johncmunson

View GitHub Profile
@johncmunson
johncmunson / piglatin.js
Created January 29, 2017 06:54
Accepts a word and returns the same word in pig latin
const pigLatin = str => {
let pigStr = "";
const key = ["a", "e", "i", "o", "u"];
if (key.some(val => val === str.charAt(0))) {
pigStr = str + "way";
return pigStr;
} else {
pigStr = str.slice(1) + str.charAt(0) + "ay";
return pigStr;
}
@johncmunson
johncmunson / romanize.js
Created January 29, 2017 03:32
Accepts a number and returns the corresponding roman numeral.
var romanize = function(num) {
var rom = {
M: 1000,
CM: 900,
D: 500,
CD: 400,
C: 100,
XC: 90,
L: 50,
XL: 40,
@johncmunson
johncmunson / deromanize.js
Created January 29, 2017 03:19
Accepts a roman numeral and returns the corresponding integer.
var deromanize = function(str) {
var str = str.toUpperCase(),
validator = /^M*(?:D?C{0,3}|C[MD])(?:L?X{0,3}|X[CL])(?:V?I{0,3}|I[XV])$/,
token = /[MDLV]|C[MD]?|X[CL]?|I[XV]?/g,
key = {
M: 1000,
CM: 900,
D: 500,
CD: 400,
C: 100,