So I would like to map a resulting value to each row within a range
of values
, populate the results into a new array and paste the created array to enrich the source data.
So the callback function in the map method should check if the amount
is < > 0 and return revenue
expense
respectively. I'm struggling in defining the map method and callback function. How can I "access" the amount column? And do I need one or two parameters for the arrow function?
function example_function() {
// Get active Sheet
sheet = SpreadsheetApp.getActiveSheet()
// Get the range
range = sheet.getDataRange()
// Get its values
values = range.getValues()
// Create new array by mapping the desired results
resulting_array = values.map((a, b) => {
// "if value in current row and column b is > 0 then return "revenue", else "expense"
// what would be the app script language equivalent to this condition?
});
// Paste the created array
sheet.getRange(2, 3).setValues(resulting_array);
}
Source
Item | Amount | P&L |
---|---|---|
Shopify | -30 | |
Paypal | 40 |
Desired Outcome
Item | Amount | P&L |
---|---|---|
Shopify | -30 | Expense |
Paypal | 40 | Revenue |