JSFiddle - React, Tailwind, and code Playground

by holanicozerpa

JavaScript

String.prototype.toPigLatin = function() {
	return this
  	.trim()
    .toLowerCase()
    .replace(/(^|\s+)([aeiou][a-z]+)/gi, "$1$2yay")
    .replace(/(^|\s+)([bcdfghjklmnpqrstvwxyz]+)([a-z]+)/gi, "$1$3$2ay");
}

document.body.textContent = "Hello world!".toPigLatin();