Example workspace: Defining Functions Example Workspace
The workspace linked above contains five tables (plus the notes table). Four of them contain formulas, each multiplying the elements of the other table by a factor of two, with alternate ways of defining the needed function.
plainValue - This data table contains a plain static value, an array of numbers.
derivedValue - This table uses the array map function to multiply each element of plainValue by two. The function called by map is defined inline.
alternateDerivedView - This table also uses the array map function to multiply each element of plainValue by two. Howeever, it defines the function called by map elsewhere. It puts it in the private code section of the table. The view dropdown shows the different sections of the table, including the data, the formula and the private code sections. The private code section allows you to put constants and functions accessed from your formula, to keep the code a little cleaner.
anotherAlternateDerivedView - This table also uses the array map function to multiply each element of plainValue by two. However, it uses an external function in the call to the array map function. See testFunction below.
testFunction - This is an external function, which is used by the data table anotherAlternateDerivedView. A function table can be created as you would create a data table, except you select Add Function instead of Add Data Table. A function table behaves like a normal javacript function when called by other tables.
There is one more way to make a function inside of Apogee, a folder function. We will cover that later.