lewis
1
Hi List,
x = [ [ [ 1, 1 ], [ 1, 1 ], [ 1, 1 ] ], [ [ 1, 1 ], [ 1, 1 ], [ 1, 1 ] ], [ [ 1, 1 ], [ 1, 1 ], [ 1, 1 ] ], [ [ 1, 1 ], [ 1, 1 ], [ 1, 1 ] ] ];
y = Array.fill(4, { Array.fill(3, Array.fill(2,1) ) });
x == y; // true
x[0][0][0] = 2;
y[0][0][0] = 2;
x == y; // false
Not sure if I’m just having a senior moment,
but why are x & y no longer equivalent after performing the same operation?
Thx,
L.
lewis
2
I thinks it’s because the final array isn’t written as a function…
Yes, that’s it… Read the array output carefully to see where y is replicating the value 2 across the multiple references to the identical sub-array.
hjh
1 Like
As an aside, here’s an easier way to write this array:
z = Array.fill([4,3,2], 1);
z[0][0][0] = 2;
z == x; // true
See J concepts in SC.
2 Likes