I am trying to merge a regular array array into a nested array such that a given element of a row in the nested array is replaced with each element in the regular array but can't compile the logic into a method e.g:
a1 = [[0,0], [0,0], [0,0]]
a2 = [1,1,1]
=> [[1, 0], [1, 0], [1, 0]] or [[0, 1], [0, 1], [0, 1]]
So far I have:
a1[0][0, a2[0]] = a2[0]
a1[1][0, a2[1]] = a2[1]
a1[2][0, a2[1]] = a2[2]
Which gives the required result but this needs to be wrapped in a method such that any array sizes can be used.
zipwithmap. Ormap.with_indexona1referencinga2with the block index parameter.a1 = [[0,1], [2,3],[4,5]]anda2 = [6,7,8]. Also, it's best to ask for a specific return value for your example, rather than "this or that". If you specify "this", the return value for "that" can often be easily deduced.