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 advanced for the google docs script - it uses the arrow function which is as fas I as I understand not being supported by google docs. Trying to rewrite the code just didn't work - I am quite a beginner and while knowing how to read code adapting one is much more complicated for me. Can anyone suggest how to change back the arrow function into a seperate function?
here is the code:
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.from(id, Number)
.reduce((counter, digit, i) => {
const step = digit * ((i % 2) + 1);
return counter + (step > 9 ? step - 9 : step);
}) % 10 === 0;
}
I believe the line causing the problem is this one:
.reduce((counter, digit, i) => {
But I might as well be wrong...
Thanks!