I was tasked with writing a function that takes a string and obfuscates it. For all ‘a’ in a strong , they are converted to a 4, 'e’s go to 3, ‘o’ to 0, and ‘l’ to one. I have the correct answer, however I an having trouble wrapping my head around the functionality.
myArgs = process.argv.slice(2);
var string = myArgs[0];
function obfuscate(string) {
var newString = string.replace(/a/g, "4");
newString = newString.replace(/e/g, "3");
newString = newString.replace(/o/g, "0");
newString = newString.replace(/l/g, "1");
return newString;
}
console.log(obfuscate(string))
The word password, for example, would cone out, p4ssw0rd
Any simplified explanation to this code would be greatly appreciated.