有如下一个数组
[
{"id": 100006, "value": "40,1666"},
{"id": 100017, "value": "112,113"},
]
期望输出如下结果
['10006:40,100017:112',
'10006:40,100017:113',
'10006:1666,100017:112',
'10006:1666,100017:113',
]
亦或者输入三个或者N个数组
[
{"id": 100006, "value": "40,1666"},
{"id": 100017, "value": "112,113"},
{"id": 100018, "value": "1,2"},
]
能够输出
['10006:40,100017:112',
'10006:40,100017:113',
'10006:40,100018:1',
'10006:40,100018:2',
'10006:1666,100017:112',
'10006:1666,100017:113',
'10006:1666,100018:1',
'10006:1666,100018:2',
'100017:112,100018:1',
'100017:112,100018:2',
'100017:113,100018:1',
'100017:113,100018:2',
]
How to implement this function?
Additional: It is best to correctly output the corresponding value regardless of the length of the input array (all values in the array will be matched once). Some answers have fixed values of 0 and 1. We hope this is not the case. .
A
ScreenShot
The core is:
The first level traverses the array
The second level traverses the object properties
Try imitating "pure functional" code:
Match two by two (this is the effect the respondent wants):
In addition, add NN matching: