First, change the function to accept arguments, and validate those arguments:
[x] Alter the transliterate function so that it accepts 2 arguments: string and substitutions.
[x] Check whether string is actually a string, and throw a TypeError if it's not. (You can borrow this code from the sanitize function.)
[x] Check whether the substitutions argument is an object, and make sure that the value of every one of its properties is a string. (You can borrow this code from the sanitize function, but you should research each of the parts of the code to make sure you know how it all works.)
Now that you've verified that the user has given you the arguments they're supposed to, you can start working with them.
The string argument is the string that the user wants to convert to another writing system.
The substitution argument is supposed to be an object with a list of replacements to make, so that the properties are the string to replace, and the values of those properties are the strings to replace them with. For example, the following substitutions object:
would make the substitutions we talked about in our last meeting. So it would change chitimacha is cool to cetemaca es kool.
The rest of the steps from here are up to you. You'll fill in the rest of the function so that it performs the tasks we discussed in our meeting:
It should check whether the output of any of the substitutions is also an input to another substitution.
If you do have a case of an input-output problem, substitute the character for some other temporary string first.
Make all the other substitutions.
Go back and replace your temporary strings with the correct ones.
I'd suggest writing the part that does the simple substitutions first. Then once that's working, you can add the parts that handle the input-output problem.
Be sure to run your code a lot to see what the output is, and check whether anything is breaking.
If you have questions or need help as you go, sync your code to GitHub and open an issue for me. Good luck!
First, change the function to accept arguments, and validate those arguments:
[x] Alter the
transliterate
function so that it accepts 2 arguments:string
andsubstitutions
.[x] Check whether
string
is actually a string, and throw a TypeError if it's not. (You can borrow this code from thesanitize
function.)[x] Check whether the
substitutions
argument is an object, and make sure that the value of every one of its properties is a string. (You can borrow this code from thesanitize
function, but you should research each of the parts of the code to make sure you know how it all works.)Now that you've verified that the user has given you the arguments they're supposed to, you can start working with them.
The
string
argument is the string that the user wants to convert to another writing system.The
substitution
argument is supposed to be an object with a list of replacements to make, so that the properties are the string to replace, and the values of those properties are the strings to replace them with. For example, the followingsubstitutions
object:would make the substitutions we talked about in our last meeting. So it would change
chitimacha is cool
tocetemaca es kool
.The rest of the steps from here are up to you. You'll fill in the rest of the function so that it performs the tasks we discussed in our meeting:
I'd suggest writing the part that does the simple substitutions first. Then once that's working, you can add the parts that handle the input-output problem.
Be sure to run your code a lot to see what the output is, and check whether anything is breaking.
If you have questions or need help as you go, sync your code to GitHub and open an issue for me. Good luck!