xuanbingbingo
class Utils {
    swapArray(arr, index1, index2) {
      arr[index1] = arr.splice(index2, 1, arr[index1])[0];
      return arr;
    },

    // 上移 将当前数组index索引与后面一个元素互换位置,向数组后面移动一位
    moveUp(arr, index) {
      this.swapArray(arr, index, index - 1);
    },

    // 下移 将当前数组index索引与前面一个元素互换位置,向数组前面移动一位
    moveDown(arr, index) {
      this.swapArray(arr, index, index + 1);
    },
}

  

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-06
  • 2022-02-19
  • 2022-12-23
  • 2021-08-06
  • 2022-12-23
  • 2021-07-16
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-08
  • 2021-05-15
相关资源
相似解决方案