均分6個....
发布于 2 年前 作者 qjzd 611 次浏览 来自 码农
  // 从大到小排序
  const len = this.data.length
  if (len <= 6) {
  return this.data
  }
  const step = Math.floor((len - 2) / 4)
  const processedData = []
  processedData.push(this.data[0])
  for (let i = 1; i <= 4; i++) {
  processedData.push(this.data[0 + i * step])
  }
  processedData.push(this.data[len - 1])
  return processedData
1 回复
function stepData (data, num) {
  const len = data.length
  if (len <= num) {
  return data
  }
  const step = Math.floor((len - 2) / (num - 2))
  const processedData = []
  processedData.push(data[0])
  for (let i = 1; i <= (num - 2); i++) {
  processedData.push(data[0 + i * step])
  }
  processedData.push(data[len - 1])
  return processedData
}
回到顶部