coming-up-smurfy
Version:
makes your sentences more smurfier
36 lines (33 loc) • 1.09 kB
JavaScript
;
/**
* CSCI 390
* HW4: Node Modules
* coming-up-smurfy.js
*
* This module holds the command which searches coming-up-smurfy.json for
* smurf words to translate. Smurf words based off of
* https://smurfsfanon.fandom.com/wiki/Smurf_(language)#2
*
* @author Elizabeth Tyler
*/
const smurfy = require("./coming-up-smurfy.json");
/**
* Goes through each word in the phrase and replaces them with the smurf
* equivalent, then returns the smurfified string. Doesn't work with
* punctuation.
*
* @param {String} phrase The phrase to be smurfified
* @returns {String} The smurfified phrase
*/
exports.translate = function(phrase) {
var newPhrase = "";
var splitPhrase = phrase.split(" ");
for (let i = 0; i < splitPhrase.length; i++) {
for (let j = 0; j < smurfy.length; j++) {
if (splitPhrase[i] == smurfy[j].word) splitPhrase[i] = smurfy[j].smurfed;
}
newPhrase += splitPhrase[i];
if (i < splitPhrase.length - 1) newPhrase += " ";
}
return newPhrase;
}