Given the files below:

file1:

```
7997,1
7997,2
7997,3
5114,1
5114,2

```

file2:

```
7997,52,
5114,12,
4221,52,

```

How can I create an array from the 1st file that has the first column as indices and the second as values to be compared with data in `file2` in awk? 

Something like this:

```
cat file1 file2 | awk -F, '{if(NF==2){arr[$1]=$2}else{if(arr[$1]){print arr[$1]","$0}}}'

```

Where the desired output would be:

```
1,2,3,7997,52
1,2,5114,12

```