给定以下 js 数组:
var prices_A =[
['company','100g','200g','300g'],
['business_a','40€','50€',''],
['business_b','50€','61€','42€'],
['business_c','66€','','31€']
]
var prices_B =[
['company','100g','200g','300g'],
['business_b','40€','50€',''],
['business_d','50€','61€','42€'],
['business_e','66€','','31€']
]
var prices_C =[
['company','100g','200g','300g'],
['business_e','40€','50€',''],
['business_b','66€','','31€']
]
如何使函数传递两个变量:grams 和 price_type,返回一个基于输入(传递的变量)合并数组的数组。price_type 可以是:prices_A、prices_B、prices_C 或prices_all。当prices_all 被引入时,它应该查询合并所有的价格(prices_A、prices_B 和prices_C)
示例 1:
var prices = myfunction(200,prices_C){}
结果:
prices =[
['company','200g'],
['business_e','50€']
]
示例 2:
var prices = myfunction(100,prices_all){}
结果:
prices =[
['company','100g_A','100g_B','100g_C'],
['business_a','40€',''],
['business_b','50€','40€','66€'],
['business_c','66€',''],
['business_d','','50€',''],
['business_e','','66€','40€'],
]
翻阅古今
相关分类