JavaScript Inputting an array into Math.Max in Google Apps Scripts inputting into array java,inputting data into array java,inputting

In a Google sheet, I have a custom form based off of some posts/blogs that I have found online to learn more about Google App Scripts. The form works correctly but I am having trouble with the column that should be creating an ID for the row.

From my reading, it seems that my problem is that math.max() takes a list not an array. Furthermore, none of the methods that I found for regular Javascript seem to be working in Google Apps Scripts. Such as, math.max.apply(null,array).

Do I have to iterate the array or is there something to make max() take an array?

Here is the code that I have been playing with.

function itemAdd(form) {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheets()[0];
  var sh = SpreadsheetApp.getActiveSheet();
  var lRow = sh.getLastRow();
  var range = sh.getRange(3,1,lRow,1);
  var maxNum = Math.max(range)
  sheet.appendRow([maxNum,form.category, form.item, form.manupub, 
form.details, form.quantity]);
  return true;
}
Answer:1

You can use Math.max.apply() at GAS. And data retrieved by getValues() is a 2 dimensional array. So in order to use the data for Math.max.apply(), the array has to be flattened. By reflecting this, the sample script can be modified as follows.

Script :

function itemAdd(form) {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheets()[0];
  var sh = SpreadsheetApp.getActiveSheet();
  var lRow = sh.getLastRow();
  var range = sh.getRange(3,1,lRow,1);
  var ar = Array.prototype.concat.apply([], range.getValues());
  var maxNum = Math.max.apply(null, ar);
  sheet.appendRow([maxNum,form.category, form.item, form.manupub, form.details, form.quantity]);
  return true;
}

If I misunderstand your question, I'm sorry.

Answer:2

Im using ReactJS with React-Router for a dashboard style application. App.js <div> <Toolbar/> <RouteHandler lang={this.state.lang} account={this.state.account} logout={this....

Im using ReactJS with React-Router for a dashboard style application. App.js <div> <Toolbar/> <RouteHandler lang={this.state.lang} account={this.state.account} logout={this....

I am creating a function that takes in an array of unsorted integers and returns an array of the unique integers, sorted by frequency. However, if the integers have the same frequency, they will be ...

I am creating a function that takes in an array of unsorted integers and returns an array of the unique integers, sorted by frequency. However, if the integers have the same frequency, they will be ...

I want to sort an array based on an sort order. public array1: Array<string> = []; array.push(some string values); //E.g dog,apple,man I have a sort order like dog = 1 apple = 3 man = 2 So ...

I want to sort an array based on an sort order. public array1: Array<string> = []; array.push(some string values); //E.g dog,apple,man I have a sort order like dog = 1 apple = 3 man = 2 So ...

  1. typescript array sorting
  2. typescript array sorting string
  3. typescript array sort by property
  4. typescript array sort by date
  5. typescript array sort alphabetically
  6. typescript array sort descending
  7. typescript array sort compare function
  8. typescript array sort example
  9. typescript array sort function
  10. typescript array sort multiple fields
  11. typescript array sort ascending
  12. typescript array sort by key
  13. typescript array sort not working
  14. typescript array sort objects
  15. typescript array sort by number
  16. typescript array sort by value
  17. typescript array sort desc
  18. typescript array sort by field
  19. typescript array sort by name
  20. typescript array sort lambda

I've been trying to use Google charts with react. It works well, but I've moved the data from a local file to a mongoDB, which gives me a date-issue. With my test-data I added a correct data-format ...

I've been trying to use Google charts with react. It works well, but I've moved the data from a local file to a mongoDB, which gives me a date-issue. With my test-data I added a correct data-format ...

  1. google charts json example
  2. google charts json to datatable
  3. google charts json format
  4. google charts json data
  5. google charts json
  6. google charts json data javascript
  7. google charts json input example
  8. google charts json file
  9. google charts json data format
  10. google charts json php
  11. google charts json data source
  12. google charts json date
  13. google charts json input
  14. google charts json datetime
  15. google charts json ajax
  16. google charts using json data
  17. google charts arraytodatatable json
  18. google charts load json
  19. google charts timeline json
  20. google charts api json