Answer the question
In order to leave comments, you need to log in
How to repeat an array N times?
In the AG column, the original array (AG2:AG10) , in the AH column, the array that I want to get at the output (the array in the AG column is duplicated 3 times). BUT when I use a large database or display a lot of value, errors appear on the limit of formulas.
Is there a workaround or a ready script?
Taking into account that the input array is not less than 3000 lines, and the output array is 40000 lines long.
The formulas that I tried give errors:
=TRANSP(split(REPEAT(join(";",AG2:AG10)&";",9999),";"))
The number of characters as a result of the REPT function exceeds the limit (32000).
or
=TRANSP(split(REPEAT(join(";",AG2:AG20000)&";",11),";"))
The number of characters resulting from the JOIN function exceeds the limit (50000).
=ArrayFormula(TRANSPOSE(SPLIT(REPEAT(CONCATENATE(AG2:AG10&"~"),1000),"~")))
Answer the question
In order to leave comments, you need to log in
=TRANSPOSE(split(rept(join(";";AG:AG)&";";3);";"))
1. Range of cells (array)
2. How many times to repeat
/**
* Дублирует массив
* Telegram - @ProgrammerForever
*
* @param {Range} arr Массив
* @param {number} count Сколько раз дублировать. По умолчанию 1
* @param {boolean} isFilter Указывает, нужно ли фильтровать строки исходного массива
* @param {number} column Номер столбца по которому надо фильтровать строки. По умолчанию 1.
* @return Дублированный массив
* @customfunction
*/
function array_repeat(arr, count=1, isFilter, column=1) {
if (isFilter){
column = -1+column;
arr = arr.filter(row=>row[column]);
};
// Вариант 1
/*
let outData = [];
for(let i=0; i<=count; i++){
outData = [...outData, ...arr];
};
*/
// Вариант 2, должен работать шустрее
let outData = new Array(arr.length*count);
for(let i=0; i<=arr.length*count; i++){
outData[i]=arr[i%arr.length];
};
return outData;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question