I am trying to create a custom function in Google Sheets which will copy a range of values vertically a given number of times:
So that when applying repeat(A1:A4,3), it pastes vertically A1 3 times, A2 3times, A3 3 times and A4 3 times.
My attempt seems to work well, displaying the result correctly, but it gives an error which I don't understand.
function repeat(range,number){
var result = [];
const l = range.length;
for (var i=0;i<len<i++)
for(var j=0;j<number;j++)
result.push(range[i])
return result;
}
The error displayed by Apps Script is: "TypeError: Cannot read property 'length' of undefined", indicating line 3. Please feel free to guide me on how to use this and whether there are easier/better options, as I am a beginner in both Apps Script and JS.