I have entered the array in the format :
let in = [{name: "Milos", repeat: null},{name: "Milos1", repeat: 2},{name: "Milos2", repeat: null},{name: "Milos3", repeat: 4}, .... ];
What is key here, the key is the repeat property.
What that means,
If any item in the array has repeat property, that item must be repeatable in the array, which means, will be placed in position n, with n repeat times, array what is expected as result is :
let out = [
{name: "Milos", repeat: null},
{name: "Milos1", repeat: 2},
{name: "Milos2", repeat: null},
{name: "Milos1", repeat: 2},
{name: "Milos3", repeat: 4}, ....,
{name: "Milos1", repeat: 2}, ...
{name: "Milos3", repeat: 4}, ...,
{name: "Milos1", repeat: 2}, ...
{name: "Milos3", repeat: 4}, ...];
Note: Dots means items with repeat property null.
Limitation, I don't want to expand the array is there no more space for that.