First time here? Check out the FAQ!
x

How to create an array that selects from arrays?

+2 votes
159 views

Hi there,

Got the following code:

| Array1 Array2 Array3 |
Array1 := #(1 2 3).
Array2 := #(4 5 6).

Array3 := (0 to: 2) collect: [ :i | !Selection of: #({i of: Array1}{i of: Array2})].

But of course it doesn't work.. So my question is: How can I create an array where each element is a selection of array elements? 

Thanks!

asked Feb 10, 2016 in Capytalk & Smalltalk by kymaguy (Virtuoso) (10,580 points)

1 Answer

+2 votes
 
Best answer

| Array1 Array2 Array3 |
Array1 := #(1 2 3).
Array2 := #(4 5 6).

Array3 := 0 to: 2 collect: [ :i | !Selection of: (Array with: (i of: Array1) with: (i of: Array2))].

Expressions in curly braces are evaluated before the rest of the Smalltalk code is evaluated.

answered Feb 10, 2016 by ssc (Savant) (107,020 points)
selected Feb 11, 2016 by kymaguy
Accessing full contents of Two Dimensional arrays
Is it possible to select the entire coontents of Array1 Or Array2 to  with a !hotVariable to populate a parameter field?

 

Ty
...