利用js中的arguments

1 传道的参数如果有一个不是数组返回【】
1/如果最长的数组有委个,好返回这些数组的集
1传递的数组长度都一样返回【】
1/如果只传道一个数组则返回原数组

es6 语法


function mergeArrays(...arrays) {
  const maxLength = Math.max(...arrays.map(arr => arr.length)); // 获取最长数组的长度
  const result = [];
  for (let i = 0; i < maxLength; i++) {
    const items = [];
    for (let j = 0; j < arrays.length; j++) {
      if (Array.isArray(arrays[j])) {
        items.push(arrays[j][i]); // 将数组中对应的元素添加到 items 中
      } else {
        return []; // 如果传递的参数中存在非数组,则返回空数组
      }
    }
    result.push(items); // 将 items 添加到 result 中
  }
  return result;
}
function mergeArray(...arrays) {
  if (arrays.length === 0) {
    return []; // 如果没有传递数组参数,则返回空数组
  }
  if (arrays.length === 1) {
    return arrays[0]; // 如果只传递了一个数组,则返回原数组
  }
  return mergeArrays(...arrays); // 否则合并数组
}

arguments

function mergeArrays() {
  const maxLength = Math.max(...arguments.map(arr => arr.length)); // 获取最长数组的长度
  const result = [];
  for (let i = 0; i < maxLength; i++) {
    const items = [];
    for (let j = 0; j < arguments.length; j++) {
      if (Array.isArray(arguments[j])) {
        items.push(arguments[j][i]); // 将数组中对应的元素添加到 items 中
      } else {
        return []; // 如果传递的参数中存在非数组,则返回空数组
      }
    }
    result.push(items); // 将 items 添加到 result 中
  }
  return result;
}
function mergeArray() {
  if (arguments.length === 0) {
    return []; // 如果没有传递数组参数,则返回空数组
  }
  if (arguments.length === 1) {
    return arguments[0]; // 如果只传递了一个数组,则返回原数组
  }
  return mergeArrays(...arguments); // 否则合并数组
}

https://blog.csdn.net/fuhanghang/article/details/110930595