Suppose I have an array :
const A = [1,2,3]
and I want to fill another array, say B, with the elements of A; B.length >> A.length.
I am interested in any function that can help create array B of the form:
[1,1,1,2,2,2,2,2,3,3,3,3,2,2,2,1,3,1]
The placements of the elements of A into B depends on specified index limits. Element 1 can be placed in several specified location/interval in B. The length of B is known; N is the length of B.
In my trial, I tried to use the array.fill function, but don't know how to get the start and end indexes. Any help will be appreciated.
const A = [1,2,3];
const B = [];
for (let k = 0; k < A.length; k++){
for (let j = 0; j < N; j++){
B.fill(A[k], start_index[j], end_index[j]);
}
}
start_indexandend_index?AintoBwithout that information.