Automating project budgets I use this code in a GAS (Google Apps Script) to automate my project budgets. 

Since every project has its own spreadsheet but all functions are in the same script file, being called as a library, I can't use them directly. I need to call libraryName.functionName, but it can't serve any arguments unless I do this:

function funcoesOrcamento( funcao, args ){
  if(args)
    args = args.split("\!|");
  else
    args = [];

  switch( args.length ){
    case 0:
      return FuncoesOrcamentoV2[ funcao ]();
    case 1:
      return FuncoesOrcamentoV2[ funcao ]( args[0] );
    case 2:
      return FuncoesOrcamentoV2[ funcao ]( args[0], args[1] );
    case 3:
      return FuncoesOrcamentoV2[ funcao ]( args[0], args[1], args[2] );
    case 4:
      return FuncoesOrcamentoV2[ funcao ]( args[0], args[1], args[2], args[3] );
    case 5:
      return FuncoesOrcamentoV2[ funcao ]( args[0], args[1], args[2], args[3], args[4] );
  }
}


Is there any way to make this more elegant and accept any number of args?
You can use .apply() which takes an array of arguments and those arguments will then be passed to the actual function as a series of normal arguments:

function funcoesOrcamento( funcao, args ){
  if(args)
    args = args.split("\!|");
  else
    args = [];

  return FuncoesOrcamentoV2[ funcao ].apply(this, args);
}


You can read more about .apply() here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply