我们需要编写一个JavaScript函数,该函数接受任意数量的Numbers数组。我们的函数应返回从数组的输入数组中选取的最大数的数组。输出数组中的元素数应等于原始输入数组中包含的子数组数。
为此的代码将是-
const arr1 = [117, 121, 18, 24];
const arr2 = [132, 19, 432, 23];
const arr3 = [32, 23, 137, 145];
const arr4 = [900, 332, 23, 19];
const mergeGreatest = (...arrs) => {
const res = [];
arrs.forEach(el => {
el.forEach((elm, ind) => {
if(!( res[ind] > elm)) {
res[ind] = elm;
};
});
});
return res;
};
console.log(mergeGreatest(arr1, arr2, arr3, arr4));输出结果
控制台中的输出将是-
[ 900, 332, 432, 145 ]