Tableau does not allow you to construct your own functions; you can only mix and match the functions offered to create your own methods/logic. Personally, I use Google Keep to keep track of any snippets (ranging from real code to Tableau functions) that I think may be useful in the future.
Tableau suggests manipulating data at the database level (i.e. using custom SQL queries) or utilising a data blending/cleaning tool if you need to do so significantly (an opensource that comes to mind is Pentaho Data Integration).