function getIDX(idx, length){
return idx <= length ? idx : getIDX(idx-length, length);
}
const newArrayLength = 10000;
const sourceArray = [1,2,3, "Hello", "World", 4, 5];
const resultArray = [];
for(let i=0; i<newArrayLength; i++){
resultArray[i]=sourceArray[getIDX(i+1, sourceArray.length)-1];
}
let array = [1,2,3, "Hello", "World", 4, 5];
let length = 10000;
const fromLength = Math.ceil(length / array.length);
let result = Array.from( { length: fromLength }, () => array )
.flat()
.slice(0, length);
function* repeatingSequence(arr, limit) {
for(let i = 0; i < limit; i++) {
const index = i % arr.length;
yield arr[index];
}
}
const generator = repeatingSequence([1,2,3, "Hello", "World", 4, 5], 10000);
const result = Array.from(generator);
function getIDX(idx, length){
if (length === 1) {return idx};
const magicNumber = length * (Math.ceil(idx/length)-1);
return idx - magicNumber;
}
const newArrayLength = 10000;
const sourceArray = [1,2,3, "Hello", "World", 4, 5];
const resultArray = [];
for(let i=0; i<newArrayLength; i++){
resultArray[i]=sourceArray[getIDX(i+1, sourceArray.length)-1];
}