I have tried implementing a piece of simple code as a script in google docs. It\'s function is validating ID numbers. The problem is that the syntax used for this code is too ad
Edit: Arrow functions are currently supported with the V8 engine. See: https://developers.google.com/apps-script/guides/v8-runtime#arrow_functions
Google Apps Script (GAS) doesn't support ECMAScript 2015 (ES6) yet. Unfortunately, in the current stage, the functions which was added from ES6 cannot be used. So it is required to convert such functions for GAS. In your script, also such functions are used. So how about this modification?
Array.from()
cannot be used at GAS.
Array.map()
.function isValidIsraeliID(id) {
var id = String(id).trim();
if (id.length > 9 || id.length < 5 || isNaN(id)) return false;
// Pad string with zeros up to 9 digits
id = id.length < 9 ? ("00000000" + id).slice(-9) : id;
return Array.map(id, Number) // Modified
.reduce(function(counter, digit, i) { // Modified
const step = digit * ((i % 2) + 1);
return counter + (step > 9 ? step - 9 : step);
}) % 10 === 0;
}
If this result was not what you want, please tell me. I would like to modify it.
Just replace the arrow function with a function:
.reduce(function(counter, digit, i) {