copyArray.js 489 Bytes
Newer Older
徐立's avatar
徐立 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/**
 * Copies the values of `source` to `array`.
 * 将“source”的值复制到“array”
 * @private
 * @param {Array} source 要从中复制值的数组.
 * @param {Array} [array=[]] 要将值复制到的数组.
 * @returns {Array} 返回数组.
 */
function copyArray(source, array) {
  let index = -1
  const length = source.length

  array || (array = new Array(length))
  while (++index < length) {
    array[index] = source[index]
  }
  return array
}

export default copyArray