Say I've got an array like this:
array_1 = [0, 0, 1, 2, 3, 0]
and another one like this:
array_2 = [4, 5, 6]
How can I create an array like this, such that each 0 in the array_1
is replaced by the first and subsequent elements of the array_2
?:
[4, 5, 1, 2, 3, 6]
That is, every time we encounter a 0
in the first array, we'd like to replace it with the result of array_2.shift
.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…