I like writing my own formulas inside of Google Docs Spreadsheets. But often what I want to do is very similar to a function that already exists. As an example,
In your custom appscript, you can use the in-built formulas of google spreadsheet in this way:
Lets say you want to use =WEEKDAY()
function on cell A1.
Then, get your active spreadsheet like this in your custom appscript function:
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("YOUR_SHEET_NAME");
now, set the formula like this:
sheet.getRange("A1").setValue("=WEEKDAY()");
Also, if you want to convert 0,1 etc to Sunday,Monday...then define an array like this:
var days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
And then use:
var dayIndex = sheet.getRange("A1").getValue();
Logger.log(days[dayIndex]);
You can see the logs using ctrl+enter or by going to View->Logs in script editor itself.